Submission #913810

#TimeUsernameProblemLanguageResultExecution timeMemory
913810alexddTents (JOI18_tents)C++17
48 / 100
154 ms216268 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9+7; int n,m; int dp[305][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<=m;cnt1++) { for(int cnti=0;cnti+cnt1<=m;cnti++) { dp[i][cnt1][cnti] += dp[i-1][cnt1][cnti];///daca nu punem niciun cort pe linia i if(cnt1-1>=0) dp[i][cnt1][cnti] += dp[i-1][cnt1-1][cnti] * (m-cnti-cnt1+1); if(cnti-1>=0) dp[i][cnt1][cnti] += dp[i-1][cnt1+1][cnti-1] * (cnt1+1); if(cnti-2>=0) dp[i][cnt1][cnti] += (dp[i-1][cnt1][cnti-2] * (m-cnt1-cnti+2)*(m-cnt1-cnti+1)/2)%MOD; dp[i][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][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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...