#include <stdio.h>
int K,W,H;
const int mod = 1000000007;
int A[303][303];
int B[303];
int Bp[303][303];
int D[303][303];
int dat[303];
int main()
{
scanf("%d%d%d",&K,&W,&H);
for(int i = 0; i < K;i ++){
scanf("%d",&dat[i]);
dat[i]--;
}
for(int i = 0; i < K; i++){
A[i][0] = 1;
for(int k = 0; k < K; k ++){
if (dat[k] != i) continue;
// length is k + 1, color is i
for(int j = 0; j + k + 1 <= W; j++) {
A[i][j + k + 1] |= A[i][j];
}
}
}
B[0] = 1;
for(int i = 1; i <= W; i ++) {
B[i] = 0;
for(int j = 1; j <= i; j++) {
for(int k = 0; k < K; k ++){
if (A[k][j]) {
int val = B[i-j] - Bp[i-j][k];
if (val < 0)
{
val += mod;
val %= mod;
}
B[i] = (B[i] + val) % mod;
Bp[i][k] = (Bp[i][k] + val) % mod;
}
}
}
}
for(int i = 0; i <= H; i++){
for(int j = 0; j <= W; j++) {
if (i == 0 || j == 0) {
D[i][j] = 1;
continue;
}
D[i][j] = (long long)D[i-1][j] * (long long)B[j] % mod;
for(int k = 0; k < j; k++) {
long long tmp = D[i][j-k-1];
tmp *= D[i-1][k];
tmp %= mod;
tmp *= B[k];
tmp %= mod;
D[i][j] = (D[i][j] + tmp) % mod;
}
}
}
printf("%d\n", D[H][W]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2164 KB |
Output is correct |
2 |
Correct |
0 ms |
2164 KB |
Output is correct |
3 |
Correct |
0 ms |
2164 KB |
Output is correct |
4 |
Correct |
0 ms |
2164 KB |
Output is correct |
5 |
Correct |
0 ms |
2164 KB |
Output is correct |
6 |
Correct |
0 ms |
2164 KB |
Output is correct |
7 |
Correct |
0 ms |
2164 KB |
Output is correct |
8 |
Correct |
4 ms |
2164 KB |
Output is correct |
9 |
Correct |
4 ms |
2164 KB |
Output is correct |
10 |
Correct |
4 ms |
2164 KB |
Output is correct |
11 |
Correct |
28 ms |
2164 KB |
Output is correct |
12 |
Correct |
28 ms |
2164 KB |
Output is correct |
13 |
Correct |
12 ms |
2164 KB |
Output is correct |
14 |
Correct |
24 ms |
2164 KB |
Output is correct |
15 |
Correct |
4 ms |
2164 KB |
Output is correct |
16 |
Correct |
100 ms |
2164 KB |
Output is correct |
17 |
Correct |
128 ms |
2164 KB |
Output is correct |
18 |
Correct |
160 ms |
2164 KB |
Output is correct |
19 |
Correct |
140 ms |
2164 KB |
Output is correct |
20 |
Correct |
152 ms |
2164 KB |
Output is correct |