Submission #963097

#TimeUsernameProblemLanguageResultExecution timeMemory
963097studySkyscraper (JOI16_skyscraper)C++17
15 / 100
1777 ms394320 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1<<14, inf = LLONG_MAX/2, mod = 1e9+7; int dp[15][101][N]; vector<int> a; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int n,L; cin >> n >> L; a = vector<int>(n+1); for (int i=1; i<=n; ++i){ cin >> a[i]; } fill_n(&dp[0][0][0],15*N*101,0); dp[0][0][0] = 1; for (int mask=0; mask<(1<<n); ++mask){ for (int sum=0; sum<=L; ++sum){ for (int last=0; last<=n; ++last){ if (last != 0 and !(mask&(1<<(last-1)))) continue; for (int unused=1; unused<=n; ++unused){ if (unused == last or !(mask&(1<<(unused-1)))) continue; int sum2 = sum; if (last != 0) sum2 += abs(a[unused]-a[last]); if (sum2 <= L){ dp[unused][sum2][mask] += dp[last][sum][mask-(1<<(unused-1))]; dp[unused][sum2][mask] %= mod; } } } } } int ans = 0; for (int k=0; k<=n; ++k){ for (int j=0; j<=L; ++j){ ans += dp[k][j][(1<<n)-1]; ans %= mod; } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...