Submission #912501

#TimeUsernameProblemLanguageResultExecution timeMemory
912501fanwenSkyscraper (JOI16_skyscraper)C++17
100 / 100
34 ms28844 KiB
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; int n, L, a[101]; long long dp[101][101][1005][3]; signed main() { cin >> n >> L; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); if(n == 1) { cout << 1; return 0; } dp[1][1][0][0] = 1; dp[1][1][0][1] = 2; for (int i = 1; i < n; ++i) { for (int j = 1; j <= i; ++j) { for (int k = 0; k <= L; ++k) { for (int e = 0; e < 3; ++e) { if(dp[i][j][k][e] == 0) continue; int new_cost = k + (a[i + 1] - a[i]) * (2 * j - e); if(new_cost > L) continue; (dp[i + 1][j + 1][new_cost][e] += dp[i][j][k][e] * (j + 1 - e)) %= Mod; (dp[i + 1][j][new_cost][e] += dp[i][j][k][e] * (2 * j - e)) %= Mod; (dp[i + 1][j - 1][new_cost][e] += dp[i][j][k][e] * (j - 1)) %= Mod; if(e < 2) { (dp[i + 1][j + 1][new_cost][e + 1] += dp[i][j][k][e] * (2 - e)) %= Mod; (dp[i + 1][j][new_cost][e + 1] += dp[i][j][k][e] * (2 - e)) %= Mod; } } } } } long long ans = 0; for (int i = 0; i <= L; ++i) { ans += dp[n][1][i][2]; ans %= Mod; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...