#include <bits/stdc++.h>
#pragma GCC optimize("O1")
#define int long long
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
const int MAXN = 110;
const double SMALL = 1e-6;
const int INF = 5e5+10;
const int MX = 2e12;
const int MOD = 1e9+7;
typedef pair<int,int> pii;
typedef pair<pii,int> ipii;
int sum(int a, int b){
return (a+b)%MOD;
}
int sub(int a, int b){
return (a+MOD-b)%MOD;
}
int mul(int a, int b){
return (a*b)%MOD;
}
int dp[110][110][1010][4]; // dp[id][cc][sum][co]
int a[110];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, L; cin >> n >> L;
for(int i=1; i<=n; i++) cin >> a[i];
sort(a+1, a+n+1);
dp[1][1][0][0] = 1; dp[1][1][0][1] = 2; dp[1][1][0][2] = 1;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int k=0; k<=L; k++){
for(int co=0; co<=2; co++){
int dif = a[i+1]-a[i]; int te = k + dif*(2*j-co);
if(te > L) continue;
// O+O j-1
dp[i+1][j-1][te][co] = sum(mul(j-1, dp[i][j][k][co]), dp[i+1][j-1][te][co]);
// O+ 2j-co
dp[i+1][j][te][co] = sum(mul(2*j-co, dp[i][j][k][co]), dp[i+1][j][te][co]);
// O+| 2-co
dp[i+1][j][te][co+1] = sum(mul(2-co, dp[i][j][k][co]), dp[i+1][j][te][co+1]);
// + j+1-co
dp[i+1][j+1][te][co] = sum(mul(j+1-co, dp[i][j][k][co]), dp[i+1][j+1][te][co]);
// +| 2-co
dp[i+1][j+1][te][co+1] = sum(mul(2-co, dp[i][j][k][co]), dp[i+1][j+1][te][co+1]);
//if(dp[i][j][k][co] != 0){
// cout << i << ' ' << j << ' '<< k << ' ' << co << ' '<< dp[i][j][k][co]<<'\n';
//}
}
}
}
}
int ans = 0;
for(int i=0; i<=L; i++) ans = sum(ans, dp[n][1][i][2]);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
1876 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
840 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
1992 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
2 ms |
1620 KB |
Output is correct |
3 |
Correct |
2 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
2 ms |
1620 KB |
Output is correct |
6 |
Correct |
2 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
2 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
1876 KB |
Output is correct |
6 |
Correct |
3 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
840 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
1992 KB |
Output is correct |
10 |
Correct |
1 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
1236 KB |
Output is correct |
12 |
Correct |
2 ms |
1620 KB |
Output is correct |
13 |
Correct |
2 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
2 ms |
1620 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1492 KB |
Output is correct |
19 |
Correct |
2 ms |
1620 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
292 ms |
167232 KB |
Output is correct |
23 |
Correct |
294 ms |
160832 KB |
Output is correct |
24 |
Correct |
279 ms |
158004 KB |
Output is correct |
25 |
Correct |
319 ms |
165712 KB |
Output is correct |
26 |
Correct |
273 ms |
148824 KB |
Output is correct |
27 |
Correct |
122 ms |
90544 KB |
Output is correct |
28 |
Correct |
154 ms |
108352 KB |
Output is correct |
29 |
Correct |
276 ms |
164616 KB |
Output is correct |
30 |
Correct |
312 ms |
163980 KB |
Output is correct |