#include <bits/stdc++.h>
using namespace std;
const int len = 105, mod = 1e9+7;
int n, a[len], dp[len][len][1005][3];
int solve(int i, int j, int rem, int l){
if (j < 0 || rem < 0 || l > 2) return 0;
//printf("cur_state = %d, %d, %d, %d\n", i, j, rem, l);
if (i == n+1) return (j == 1 && l == 2);
if (dp[i][j][rem][l] != -1) return dp[i][j][rem][l];
int ans = 0, c = a[i+1]-a[i];
// Case 1: combine 2 ccs
if (j >= 2){
int temp = solve(i+1, j-1, rem-c*(2*(j-1)-l), l);
if (l == 0)
ans = (ans + j*(j-1)*1LL*temp)%mod;
else if (l == 1)
ans = (ans + (j-1)*(j-1)*1LL*temp)%mod;
else{
if (i == n) ans = (ans+temp)%mod;
else ans = (ans + (j-2)*(j-1)*1LL*temp)%mod;
}
}
// Case 2: create +1 cc
// do not add an endpoint
ans = (ans+solve(i+1, j+1, rem-c*(2*(j+1)-l), l))%mod;
// add an endpoint
ans = (ans+(2-l)*1LL*solve(i+1, j+1, rem-c*(2*(j+1)-l-1), l+1))%mod;
//i think its right!
// just enlarge 1 cc
if (j){
// do not add an endpoint
ans = (ans+(2*j-l)*1LL*solve(i+1, j, rem-c*(2*j-l), l))%mod;
// add an endpoint
int temp = solve(i+1, j, rem-c*(2*j-l-1), l+1);
if (i == n)
ans = (ans+(2-l)*j*1LL*temp)%mod;
else
ans = (ans+(2-l)*(j-l)*1LL*temp)%mod;
}
//if this is right...something else is wrong...
return dp[i][j][rem][l] = ans;
}
int main(){
int l;
scanf("%d %d", &n, &l);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a+1, a+n+1);
a[n+1] = a[n];
if (n == 1){
printf("1\n");
return 0;
}
for (int i = 1; i <= n; i++)
for (int j = 0; j <= n; j++)
for (int rem = 0; rem <= l; rem++)
dp[i][j][rem][0] = dp[i][j][rem][1] = dp[i][j][rem][2] = -1;
printf("%d\n", solve(1, 0, l, 0));
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &l);
^
skyscraper.cpp:54:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
131868 KB |
Output is correct |
2 |
Correct |
0 ms |
131868 KB |
Output is correct |
3 |
Correct |
0 ms |
131868 KB |
Output is correct |
4 |
Correct |
0 ms |
131868 KB |
Output is correct |
5 |
Correct |
1 ms |
131868 KB |
Output is correct |
6 |
Correct |
0 ms |
131868 KB |
Output is correct |
7 |
Correct |
0 ms |
131868 KB |
Output is correct |
8 |
Correct |
1 ms |
131868 KB |
Output is correct |
9 |
Correct |
1 ms |
131868 KB |
Output is correct |
10 |
Correct |
0 ms |
131868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
131868 KB |
Output is correct |
2 |
Correct |
1 ms |
131868 KB |
Output is correct |
3 |
Correct |
1 ms |
131868 KB |
Output is correct |
4 |
Correct |
1 ms |
131868 KB |
Output is correct |
5 |
Correct |
1 ms |
131868 KB |
Output is correct |
6 |
Correct |
0 ms |
131868 KB |
Output is correct |
7 |
Correct |
0 ms |
131868 KB |
Output is correct |
8 |
Correct |
1 ms |
131868 KB |
Output is correct |
9 |
Correct |
1 ms |
131868 KB |
Output is correct |
10 |
Correct |
1 ms |
131868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
131868 KB |
Output is correct |
2 |
Correct |
0 ms |
131868 KB |
Output is correct |
3 |
Correct |
0 ms |
131868 KB |
Output is correct |
4 |
Correct |
0 ms |
131868 KB |
Output is correct |
5 |
Correct |
1 ms |
131868 KB |
Output is correct |
6 |
Correct |
0 ms |
131868 KB |
Output is correct |
7 |
Correct |
0 ms |
131868 KB |
Output is correct |
8 |
Correct |
1 ms |
131868 KB |
Output is correct |
9 |
Correct |
1 ms |
131868 KB |
Output is correct |
10 |
Correct |
0 ms |
131868 KB |
Output is correct |
11 |
Correct |
1 ms |
131868 KB |
Output is correct |
12 |
Correct |
1 ms |
131868 KB |
Output is correct |
13 |
Correct |
1 ms |
131868 KB |
Output is correct |
14 |
Correct |
1 ms |
131868 KB |
Output is correct |
15 |
Correct |
1 ms |
131868 KB |
Output is correct |
16 |
Correct |
0 ms |
131868 KB |
Output is correct |
17 |
Correct |
0 ms |
131868 KB |
Output is correct |
18 |
Correct |
1 ms |
131868 KB |
Output is correct |
19 |
Correct |
1 ms |
131868 KB |
Output is correct |
20 |
Correct |
1 ms |
131868 KB |
Output is correct |
21 |
Correct |
0 ms |
131868 KB |
Output is correct |
22 |
Correct |
126 ms |
131868 KB |
Output is correct |
23 |
Correct |
63 ms |
131868 KB |
Output is correct |
24 |
Correct |
107 ms |
131868 KB |
Output is correct |
25 |
Correct |
88 ms |
131868 KB |
Output is correct |
26 |
Correct |
84 ms |
131868 KB |
Output is correct |
27 |
Correct |
34 ms |
131868 KB |
Output is correct |
28 |
Correct |
52 ms |
131868 KB |
Output is correct |
29 |
Correct |
96 ms |
131868 KB |
Output is correct |
30 |
Correct |
90 ms |
131868 KB |
Output is correct |