This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;
const int N = 50;
const int LEN = 10000;
int add(int a, int b){ a += b; if(a >= MOD) a -= MOD; return a;}
int mul(int a, int b){ return (1LL*a*b)%MOD; }
int a[55];
int dp[55][55][LEN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, len;
cin >> n >> len;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) a[i]--;
sort(a+1, a+1+n);
reverse(a+1, a+1+n);
dp[0][2][0] = 1;
for(int i=1; i<=n; i++){
for(int k=1; k<=i+2; k++){
int dva = 0, ddva = 0;
int jedan = 0, jjedan = 0;
for(int t=1; t<=len; t++){
/// spaja dva
ddva = add(ddva, dp[i-1][k+1][t-1]);
dva = add(dva, ddva);
dp[i][k][t] = add(dp[i][k][t], mul(k, dva));
/// pored jednog
if(t-1-a[i] >= 0) jjedan = add(jjedan, dp[i-1][k][t-1-a[i]]);
dp[i][k][t] = add(dp[i][k][t], mul(2*k-2, jjedan));
/// sam
if(k >= 2 && t-1-2*a[i] >= 0) dp[i][k][t] = add(dp[i][k][t], mul(k-2, dp[i-1][k-1][t-1-2*a[i]]));
}
}
}
cout << dp[n][1][len] << "\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:32:17: warning: unused variable 'jedan' [-Wunused-variable]
32 | int jedan = 0, jjedan = 0;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |