/*input
1 2
*/
#include<bits/stdc++.h>
using namespace std;
const int N=3011;
const int mod=1e9+7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl
//Trace prints the name of the variable and the value.
int dp[N][N];
int solve(int r, int c)
{
if(r<0||c<0) return 0;
if(r==0||c==0) return 1;
if(dp[r][c]!=-1) return dp[r][c];
int temp=solve(r, c-1);
temp+=(((r*(r-1))/2)*solve(r-2, c-1))%mod;temp%=mod;
temp+=(4*r*solve(r-1, c-1))%mod;temp%=mod;
temp+=((c-1)*r*solve(r-1, c-2));temp%=mod;
dp[r][c]=temp;return dp[r][c];
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int r, c;cin>>r>>c;
for(int i=0;i<N;i++)
for(int j=0;j<N;j++) dp[i][j]=-1;
cout<<(solve(r, c)+mod-1)%mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
71296 KB |
Output is correct |
2 |
Correct |
35 ms |
71296 KB |
Output is correct |
3 |
Correct |
35 ms |
71296 KB |
Output is correct |
4 |
Correct |
35 ms |
71296 KB |
Output is correct |
5 |
Correct |
35 ms |
71296 KB |
Output is correct |
6 |
Correct |
37 ms |
71288 KB |
Output is correct |
7 |
Correct |
35 ms |
71296 KB |
Output is correct |
8 |
Correct |
34 ms |
71288 KB |
Output is correct |
9 |
Correct |
34 ms |
71296 KB |
Output is correct |
10 |
Correct |
35 ms |
71288 KB |
Output is correct |
11 |
Correct |
36 ms |
71292 KB |
Output is correct |
12 |
Correct |
36 ms |
71296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
71296 KB |
Output is correct |
2 |
Correct |
35 ms |
71296 KB |
Output is correct |
3 |
Correct |
35 ms |
71296 KB |
Output is correct |
4 |
Correct |
35 ms |
71296 KB |
Output is correct |
5 |
Correct |
35 ms |
71296 KB |
Output is correct |
6 |
Correct |
37 ms |
71288 KB |
Output is correct |
7 |
Correct |
35 ms |
71296 KB |
Output is correct |
8 |
Correct |
34 ms |
71288 KB |
Output is correct |
9 |
Correct |
34 ms |
71296 KB |
Output is correct |
10 |
Correct |
35 ms |
71288 KB |
Output is correct |
11 |
Correct |
36 ms |
71292 KB |
Output is correct |
12 |
Correct |
36 ms |
71296 KB |
Output is correct |
13 |
Correct |
36 ms |
71424 KB |
Output is correct |
14 |
Correct |
35 ms |
71296 KB |
Output is correct |
15 |
Correct |
192 ms |
71424 KB |
Output is correct |
16 |
Correct |
60 ms |
71416 KB |
Output is correct |
17 |
Correct |
67 ms |
71424 KB |
Output is correct |
18 |
Correct |
86 ms |
71552 KB |
Output is correct |
19 |
Correct |
220 ms |
71416 KB |
Output is correct |
20 |
Correct |
188 ms |
71548 KB |
Output is correct |
21 |
Correct |
137 ms |
71416 KB |
Output is correct |
22 |
Correct |
134 ms |
71416 KB |
Output is correct |
23 |
Correct |
51 ms |
71416 KB |
Output is correct |
24 |
Correct |
295 ms |
71544 KB |
Output is correct |
25 |
Correct |
233 ms |
71672 KB |
Output is correct |
26 |
Correct |
261 ms |
71552 KB |
Output is correct |
27 |
Correct |
313 ms |
71552 KB |
Output is correct |