This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |