#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3001][3001];
ll mod = 1000000007LL;
ll go(int rows, int cols){
if(rows==0 || cols==0){
return 1LL;
}
if(dp[rows][cols]!=-1){
return dp[rows][cols];
}
ll ret = go(rows-1,cols);
if(cols>=2){
ret += ((ll)cols*(ll)(cols-1))/2LL*go(rows-1,cols-2);
ret %= mod;
}
if(rows>=2){
ret += (ll)cols*(ll)(rows-1)*go(rows-2,cols-1);
ret %= mod;
}
ret += 4LL*(ll)cols*go(rows-1,cols-1);
ret %= mod;
dp[rows][cols] = ret;
return ret;
}
int main(){
for(int a = 0; a<=3000; a++){
for(int b =0; b<=3000; b++){
dp[a][b] = -1;
}
}
int r, c;
cin >> r >> c;
cout << (go(r,c)+mod-1LL)%mod << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
70776 KB |
Output is correct |
2 |
Correct |
47 ms |
70776 KB |
Output is correct |
3 |
Correct |
49 ms |
70920 KB |
Output is correct |
4 |
Correct |
51 ms |
70972 KB |
Output is correct |
5 |
Correct |
49 ms |
70972 KB |
Output is correct |
6 |
Correct |
53 ms |
70996 KB |
Output is correct |
7 |
Correct |
54 ms |
70996 KB |
Output is correct |
8 |
Correct |
85 ms |
70996 KB |
Output is correct |
9 |
Correct |
59 ms |
71024 KB |
Output is correct |
10 |
Correct |
56 ms |
71024 KB |
Output is correct |
11 |
Correct |
54 ms |
71072 KB |
Output is correct |
12 |
Correct |
70 ms |
71072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
70776 KB |
Output is correct |
2 |
Correct |
47 ms |
70776 KB |
Output is correct |
3 |
Correct |
49 ms |
70920 KB |
Output is correct |
4 |
Correct |
51 ms |
70972 KB |
Output is correct |
5 |
Correct |
49 ms |
70972 KB |
Output is correct |
6 |
Correct |
53 ms |
70996 KB |
Output is correct |
7 |
Correct |
54 ms |
70996 KB |
Output is correct |
8 |
Correct |
85 ms |
70996 KB |
Output is correct |
9 |
Correct |
59 ms |
71024 KB |
Output is correct |
10 |
Correct |
56 ms |
71024 KB |
Output is correct |
11 |
Correct |
54 ms |
71072 KB |
Output is correct |
12 |
Correct |
70 ms |
71072 KB |
Output is correct |
13 |
Correct |
54 ms |
71072 KB |
Output is correct |
14 |
Correct |
53 ms |
71200 KB |
Output is correct |
15 |
Correct |
430 ms |
71300 KB |
Output is correct |
16 |
Correct |
70 ms |
71300 KB |
Output is correct |
17 |
Correct |
97 ms |
71300 KB |
Output is correct |
18 |
Correct |
156 ms |
71300 KB |
Output is correct |
19 |
Correct |
533 ms |
71332 KB |
Output is correct |
20 |
Correct |
449 ms |
71420 KB |
Output is correct |
21 |
Correct |
239 ms |
71420 KB |
Output is correct |
22 |
Correct |
313 ms |
71420 KB |
Output is correct |
23 |
Correct |
199 ms |
71420 KB |
Output is correct |
24 |
Correct |
646 ms |
71420 KB |
Output is correct |
25 |
Correct |
467 ms |
71456 KB |
Output is correct |
26 |
Correct |
578 ms |
71456 KB |
Output is correct |
27 |
Correct |
718 ms |
71456 KB |
Output is correct |