#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int n,m;
int dp[2][305][305];
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;
}
signed main()
{
cin>>n>>m;
dp[0][0][0]=1;
for(int i=1;i<=n;i++)
{
for(int cnt1=0;cnt1<=min(m,i);cnt1++)
{
for(int cnti=0;cnti<=min(2*i,m-cnt1);cnti++)
{
dp[i%2][cnt1][cnti] = dp[1-i%2][cnt1][cnti];///daca nu punem niciun cort pe linia i
if(cnt1-1>=0) dp[i%2][cnt1][cnti] += dp[1-i%2][cnt1-1][cnti] * (m-cnti-cnt1+1);
if(cnti-1>=0) dp[i%2][cnt1][cnti] += dp[1-i%2][cnt1+1][cnti-1] * (cnt1+1);
if(cnti-2>=0) dp[i%2][cnt1][cnti] += (dp[1-i%2][cnt1][cnti-2] * (m-cnt1-cnti+2)*(m-cnt1-cnti+1)/2)%MOD;
dp[i%2][cnt1][cnti] %= MOD;
}
}
}
int sum=MOD-1;
for(int cnt1=0;cnt1<=m;cnt1++)
for(int cnti=0;cnti+cnt1<=m;cnti++)
sum = (sum + (dp[n%2][cnt1][cnti] * put(4,cnt1))%MOD)%MOD;
cout<<sum;
return 0;
}
/**
dp[i][cnt1][cnti] = numarul de moduri de a pune corturi pe primele i randuri a.i. sa avem cnt1 coloane cu un cort pe ele si cnti coloane interzise (pe care nu mai putem pune corturi)
dp[i][cnt1][cnti] = dp[i-1][cnt1][cnti] + dp[i-1][cnt1-1][cnti] * (m - cnti - cnt1 + 1) + dp[i-1][cnt1+1][cnti-1] * (cnt1+1) + dp[i-1][cnt1][cnti-2] * (m-cnt1-cnti+2) * (m-cnt1-cnti+1) / 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
12 ms |
856 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
44 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
500 KB |
Output is correct |
10 |
Correct |
12 ms |
856 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
44 ms |
1620 KB |
Output is correct |
13 |
Runtime error |
16 ms |
344 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |