# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
913810 |
2024-01-20T09:52:19 Z |
alexdd |
Tents (JOI18_tents) |
C++17 |
|
154 ms |
216268 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
2392 KB |
Output is correct |
5 |
Correct |
27 ms |
38492 KB |
Output is correct |
6 |
Correct |
28 ms |
48724 KB |
Output is correct |
7 |
Correct |
32 ms |
47956 KB |
Output is correct |
8 |
Correct |
20 ms |
36184 KB |
Output is correct |
9 |
Correct |
2 ms |
2140 KB |
Output is correct |
10 |
Correct |
57 ms |
97340 KB |
Output is correct |
11 |
Correct |
7 ms |
7512 KB |
Output is correct |
12 |
Correct |
154 ms |
216268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
2392 KB |
Output is correct |
5 |
Correct |
27 ms |
38492 KB |
Output is correct |
6 |
Correct |
28 ms |
48724 KB |
Output is correct |
7 |
Correct |
32 ms |
47956 KB |
Output is correct |
8 |
Correct |
20 ms |
36184 KB |
Output is correct |
9 |
Correct |
2 ms |
2140 KB |
Output is correct |
10 |
Correct |
57 ms |
97340 KB |
Output is correct |
11 |
Correct |
7 ms |
7512 KB |
Output is correct |
12 |
Correct |
154 ms |
216268 KB |
Output is correct |
13 |
Incorrect |
80 ms |
4696 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |