#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int put(int a, int exp)
{
if(exp==0)
return 1;
if(exp%2==0)
return put((a*a)%MOD,exp/2);
else
return (put((a*a)%MOD,exp/2)*a)%MOD;
}
int cm[3005][3005];
int fact[6005];
int comb(int x, int y)
{
return cm[x][y];
}
int dp[3005][3005];
signed main()
{
fact[0]=1;
for(int i=1;i<=6000;i++)
fact[i]=(fact[i-1]*i)%MOD;
for(int i=0;i<=3000;i++)
{
for(int j=0;j<=i;j++)
{
if(i==j)
cm[i][j]=1;
else if(j==0)
cm[i][j]=1;
else
cm[i][j]=(cm[i-1][j-1]+cm[i-1][j])%MOD;
}
}
int n,m;
cin>>n>>m;
dp[n][m]=1;
for(int i=n;i>=0;i--)
{
for(int j=m;j>=0;j--)
{
if(i==n && j==m)
continue;
dp[i][j] += dp[i+1][j];
dp[i][j] += (dp[i+1][j+1] * (j+1) * 4LL)%MOD;
dp[i][j] += (dp[i+1][j+2] * comb(j+2,2))%MOD;
dp[i][j] += (dp[i+2][j+1] * (i+1) * (j+1))%MOD;
dp[i][j]%=MOD;
}
}
int sum=MOD-1;
for(int i=0;i<=m;i++)
sum=(sum+dp[0][i])%MOD;
cout<<sum;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
71768 KB |
Output is correct |
2 |
Correct |
17 ms |
71768 KB |
Output is correct |
3 |
Correct |
17 ms |
73820 KB |
Output is correct |
4 |
Correct |
17 ms |
74588 KB |
Output is correct |
5 |
Correct |
17 ms |
73688 KB |
Output is correct |
6 |
Correct |
18 ms |
74584 KB |
Output is correct |
7 |
Correct |
18 ms |
73820 KB |
Output is correct |
8 |
Correct |
17 ms |
74588 KB |
Output is correct |
9 |
Correct |
20 ms |
74240 KB |
Output is correct |
10 |
Correct |
18 ms |
75100 KB |
Output is correct |
11 |
Correct |
17 ms |
73820 KB |
Output is correct |
12 |
Correct |
18 ms |
75356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
71768 KB |
Output is correct |
2 |
Correct |
17 ms |
71768 KB |
Output is correct |
3 |
Correct |
17 ms |
73820 KB |
Output is correct |
4 |
Correct |
17 ms |
74588 KB |
Output is correct |
5 |
Correct |
17 ms |
73688 KB |
Output is correct |
6 |
Correct |
18 ms |
74584 KB |
Output is correct |
7 |
Correct |
18 ms |
73820 KB |
Output is correct |
8 |
Correct |
17 ms |
74588 KB |
Output is correct |
9 |
Correct |
20 ms |
74240 KB |
Output is correct |
10 |
Correct |
18 ms |
75100 KB |
Output is correct |
11 |
Correct |
17 ms |
73820 KB |
Output is correct |
12 |
Correct |
18 ms |
75356 KB |
Output is correct |
13 |
Correct |
17 ms |
71712 KB |
Output is correct |
14 |
Correct |
22 ms |
83044 KB |
Output is correct |
15 |
Correct |
74 ms |
127640 KB |
Output is correct |
16 |
Correct |
21 ms |
76628 KB |
Output is correct |
17 |
Correct |
30 ms |
84960 KB |
Output is correct |
18 |
Correct |
33 ms |
90192 KB |
Output is correct |
19 |
Correct |
79 ms |
136020 KB |
Output is correct |
20 |
Correct |
66 ms |
122448 KB |
Output is correct |
21 |
Correct |
51 ms |
105556 KB |
Output is correct |
22 |
Correct |
50 ms |
107900 KB |
Output is correct |
23 |
Correct |
40 ms |
98132 KB |
Output is correct |
24 |
Correct |
110 ms |
141704 KB |
Output is correct |
25 |
Correct |
95 ms |
133488 KB |
Output is correct |
26 |
Correct |
89 ms |
139604 KB |
Output is correct |
27 |
Correct |
97 ms |
141652 KB |
Output is correct |