Submission #941400

#TimeUsernameProblemLanguageResultExecution timeMemory
941400Hacv16Skyscraper (JOI16_skyscraper)C++17
15 / 100
434 ms91080 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 14; const int MAXL = 101; const int MOD = 1e9 + 7; int n, l, a[MAXN]; int dp[1 << MAXN][MAXN][MAXL]; int32_t main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> l; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) dp[(1 << i)][i][0] = 1; for(int mask = 1; mask < (1 << n); mask++) { for(int last = 0; last < n; last++) { if((mask & (1 << last)) == 0) continue; for(int pen = 0; pen <= l; pen++) { for(int prev = 0; prev < n; prev++) { if((mask & (1 << prev)) == 0 || prev == last) continue; int curPen = abs(a[last] - a[prev]); if(curPen <= pen) dp[mask][last][pen] = (dp[mask][last][pen] + dp[mask ^ (1 << last)][prev][pen - curPen]) % MOD; } } } } int ans = 0; for(int i = 0; i < n; i++) for(int j = 0; j <= l; j++) ans = (ans + dp[(1 << n) - 1][i][j]) % MOD; cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...