Submission #863071

#TimeUsernameProblemLanguageResultExecution timeMemory
863071TAhmed33Magneti (COCI21_magneti)C++98
110 / 110
89 ms66648 KiB
#include <bits/stdc++.h> using namespace std; int n, l, x; const int MOD = 1e9 + 7; int nCr[30500][500]; int dp1[100001][51]; int dp2[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); dp1[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= l; j++) { for (int k = 1; k <= i; k++) { dp2[j][k] = 0; if (2 * arr[i] - 1 <= j) dp2[j][k] = add(dp2[j][k], mul(mul(k + 1, k), dp1[j - 2 * arr[i] + 1][k + 1])); dp2[j][k] = add(dp2[j][k], dp1[j - 1][k - 1]); if (arr[i] <= j) dp2[j][k] = add(dp2[j][k], mul(2 * k, dp1[j - arr[i]][k])); } } for (int j = 0; j <= l; j++) { for (int k = 0; k <= n; k++) { dp1[j][k] = dp2[j][k]; } } } //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(dp1[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...