273D - Dima and Figure - CodeForces Solution


dp *2400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=155;
const int mod=1e9+7;
int f[N][N][2][2],n,m;
signed main()
{
	cin>>n>>m;int ans=0;
	for(int i=1;i<=m;i++)for(int j=i;j<=m;j++)f[i][j][1][1]=1;
	for(int i=1;i<=n;i++)
	{
		int an=0;
		for(int l=1;l<=m;l++)for(int r=l;r<=m;r++)
		 for(int p1=0;p1<=1;p1++)for(int p2=0;p2<=1;p2++)
		  an=(an+f[l][r][p1][p2])%mod;
		ans=(ans+an*(n-i+1)%mod)%mod;
		for(int l=1;l<=m;l++)for(int r=l+1;r<=m;r++)for(int p=0;p<=1;p++)
		 f[l+1][r][0][p]=(f[l+1][r][0][p]+f[l][r][0][p]+f[l][r][1][p])%mod;
		for(int l=1;l<=m;l++)for(int r=m;r>l;r--)for(int p=0;p<=1;p++)
		 f[l][r-1][p][0]=(f[l][r-1][p][0]+f[l][r][p][1]+f[l][r][p][0])%mod;	
		for(int l=m;l>1;l--)for(int r=l;r<=m;r++)for(int p=0;p<=1;p++)
		 f[l-1][r][1][p]=(f[l-1][r][1][p]+f[l][r][1][p])%mod;
		for(int l=m;l>=1;l--)for(int r=l;r<m;r++)for(int p=0;p<=1;p++)
		 f[l][r+1][p][1]=(f[l][r+1][p][1]+f[l][r][p][1])%mod;
	}
	cout<<ans<<endl;
	return 0;
}	


Comments

Submit
0 Comments
More Questions

1703E - Mirror Grid
1042A - Benches
1676B - Equal Candies
1705B - Mark the Dust Sweeper
1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets
1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game
1702B - Polycarp Writes a String from Memory
1701A - Grass Field
489C - Given Length and Sum of Digits
886B - Vlad and Cafes
915A - Garden
356A - Knight Tournament
1330A - Dreamoon and Ranking Collection
1692B - All Distinct