Submission #863056

#TimeUsernameProblemLanguageResultExecution timeMemory
863056TAhmed33Magneti (COCI21_magneti)C++98
60 / 110
116 ms253780 KiB
#include <bits/stdc++.h> using namespace std; int n, l, x; const int MOD = 1e9 + 7; int nCr[30500][500]; int dp[50][100001][51]; int add (int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int sub (int a, int b) { a -= b; if (a < 0) a += MOD; return a; } int mul (int a, int b) { return (a * 1ll * b) % MOD; } int arr[51]; int main () { cin >> n >> l; for (int i = 0; i < 30500; i++) { for (int j = 0; j <= min(499, i); j++) { if (j == 0 || j == i) { nCr[i][j] = 1; } else { nCr[i][j] = add(nCr[i - 1][j], nCr[i - 1][j - 1]); } } } for (int i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + n + 1); dp[0][0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= l; j++) { for (int k = 1; k <= i; k++) { dp[i][j][k] = 0; if (2 * arr[i] - 1 <= j) dp[i][j][k] = add(dp[i][j][k], mul(mul(k + 1, k), dp[i - 1][j - 2 * arr[i] + 1][k + 1])); dp[i][j][k] = add(dp[i][j][k], dp[i - 1][j - 1][k - 1]); if (arr[i] <= j) dp[i][j][k] = add(dp[i][j][k], mul(2 * k, dp[i - 1][j - arr[i]][k])); //cout << i << " " << j << " " << k << ": " << dp[i][j][k] << '\n'; } } } //for (int i = 1; i <= l; i++) cout << dp[n][i][1] << '\n'; int sum = 0; for (int i = 1; i <= l; i++) sum = add(sum, mul(dp[n][i][1], nCr[n - i + l][n])); cout << sum << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...