#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
int n, w, h, ok[305][305];
lint d1[305][305], sum[305];
lint dp[305][305];
int main(){
cin >> n >> w >> h;
for(int i=1; i<=n; i++) ok[i][0] = 1;
for(int i=1; i<=n; i++){
int x;
cin >> x;
for(int j=0; j+i<=w; j++){
ok[x][j+i] |= ok[x][j];
}
}
d1[0][0] = 1;
sum[0] = 1;
for(int i=1; i<=w; i++){
for(int j=1; j<=n; j++){
for(int k=0; k<i; k++){
if(ok[j][i-k]){
d1[i][j] += sum[k] - d1[k][j] + mod;
}
}
d1[i][j] %= mod;
sum[i] += d1[i][j];
}
sum[i] %= mod;
}
for(int i=0; i<=w; i++) dp[0][i] = 1;
for(int i=1; i<=h; i++){
dp[i][0] = 1;
for(int j=1; j<=w; j++){
dp[i][j] = dp[i-1][j] * sum[j] % mod;
dp[i][j] += dp[i][j-1];
for(int k=1; k<j; k++){
dp[i][j] += (dp[i-1][k] * sum[k] % mod) * dp[i][j-k-1] % mod;
}
dp[i][j] %= mod;
}
}
cout << dp[h][w];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3840 KB |
Output is correct |
2 |
Correct |
0 ms |
3840 KB |
Output is correct |
3 |
Correct |
0 ms |
3840 KB |
Output is correct |
4 |
Correct |
0 ms |
3840 KB |
Output is correct |
5 |
Correct |
0 ms |
3840 KB |
Output is correct |
6 |
Correct |
0 ms |
3840 KB |
Output is correct |
7 |
Correct |
0 ms |
3840 KB |
Output is correct |
8 |
Correct |
0 ms |
3840 KB |
Output is correct |
9 |
Correct |
3 ms |
3840 KB |
Output is correct |
10 |
Correct |
0 ms |
3840 KB |
Output is correct |
11 |
Correct |
13 ms |
3840 KB |
Output is correct |
12 |
Correct |
9 ms |
3840 KB |
Output is correct |
13 |
Correct |
6 ms |
3840 KB |
Output is correct |
14 |
Correct |
16 ms |
3840 KB |
Output is correct |
15 |
Correct |
3 ms |
3840 KB |
Output is correct |
16 |
Correct |
46 ms |
3840 KB |
Output is correct |
17 |
Correct |
69 ms |
3840 KB |
Output is correct |
18 |
Correct |
76 ms |
3840 KB |
Output is correct |
19 |
Correct |
76 ms |
3840 KB |
Output is correct |
20 |
Correct |
63 ms |
3840 KB |
Output is correct |