#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int mxn=3e3+2,M=1e9+7;
int n,m;
ll dp[3][mxn];
int main(){
cin>>n>>m;
for(int i=0;i<=m;i++){
dp[0][i]=1;
}
dp[1][0]=dp[2][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ll x1=(j>1)?(j*(j-1))/2*dp[(i+2)%3][j-2]:0;
ll x2=(i>1)?j*(i-1)*dp[(i+1)%3][j-1]:0;
ll x3=j*4*dp[(i+2)%3][j-1];
ll x4=dp[(i+2)%3][j];
dp[i%3][j]=(x1+x2+x3+x4)%M;
//cout<<dp[i%3][j]<<" ";
}
//cout<<endl;
}
cout<<dp[n%3][m]-1<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
14 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
488 KB |
Output is correct |
18 |
Correct |
6 ms |
348 KB |
Output is correct |
19 |
Correct |
17 ms |
500 KB |
Output is correct |
20 |
Correct |
13 ms |
344 KB |
Output is correct |
21 |
Correct |
9 ms |
344 KB |
Output is correct |
22 |
Correct |
9 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
464 KB |
Output is correct |
24 |
Correct |
23 ms |
344 KB |
Output is correct |
25 |
Correct |
17 ms |
348 KB |
Output is correct |
26 |
Correct |
20 ms |
504 KB |
Output is correct |
27 |
Correct |
22 ms |
348 KB |
Output is correct |