#include<bits/stdc++.h>
using namespace std;
#define N 3005
long long dp[N][N],mod=1e9+7;
int main(){
int n,m,i,j;
scanf("%d %d",&n,&m);
for(i=0;i<=n;i++)for(j=0;j<=m;j++){//dp[i][j]: consider placing up until ith row jth col
if(!i||!j)dp[i][j]=1;
else{
dp[i][j]+=dp[i-1][j];//not place in ith row
dp[i][j]+=(j*4*dp[i-1][j-1])%mod;//place 1 in ith row while moving other col
if(j>=2)dp[i][j]+=((j*(j-1)/2)*dp[i-1][j-2])%mod;// place <> choose (i,j1),(i,j2) and move others
if(i>=2)dp[i][j]+=((j*(i-1))*dp[i-2][j-1])%mod;//place up-down choose (i,j1),(i2,j1) and move others
dp[i][j]%=mod;
}
}
printf("%lld",(dp[n][m]-1+mod)%mod);
return 0;
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
1332 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
1332 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
2132 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
4 ms |
9656 KB |
Output is correct |
15 |
Correct |
179 ms |
55084 KB |
Output is correct |
16 |
Correct |
12 ms |
4008 KB |
Output is correct |
17 |
Correct |
39 ms |
12728 KB |
Output is correct |
18 |
Correct |
50 ms |
17000 KB |
Output is correct |
19 |
Correct |
206 ms |
62980 KB |
Output is correct |
20 |
Correct |
165 ms |
50768 KB |
Output is correct |
21 |
Correct |
108 ms |
33784 KB |
Output is correct |
22 |
Correct |
105 ms |
35384 KB |
Output is correct |
23 |
Correct |
63 ms |
27084 KB |
Output is correct |
24 |
Correct |
278 ms |
70828 KB |
Output is correct |
25 |
Correct |
210 ms |
61132 KB |
Output is correct |
26 |
Correct |
239 ms |
66504 KB |
Output is correct |
27 |
Correct |
269 ms |
68896 KB |
Output is correct |