1725: [usaco Nov] corn fields farm schedule time limit: 5 sec memory limit: 64 MB
Submit: 400 solved: 290
[Submit] [Status] Description
Farmer John bought a new rectangular farm which is divided into M columns and N rows (1 <= m <= 12; 1 <= n <= 12 ), each grid is a square area. FJ intends to plant delicious grass in a few plots of land on the farm for their cows to enjoy. Unfortunately, some land is quite poor and cannot be used for grazing. In addition, the cows like the feeling of monopolizing a lawn, so FJ will not choose two adjacent lands, that is, no two lawns have a public edge. Of course, FJ has not yet decided on which land to plant grass. As a curious farmer, FJ wants to know how many planting schemes are available if the total number of lawns is not considered. Of course, it is also a solution to abandon a new farm and not plant grass on any land. Please help FJ calculate the total number of solutions.
Input
* Row 1st: two positive integers m and n, separated by Spaces
* Row 2nd. m + 1: Each line contains N integers separated by spaces, which describe the status of each land. The entered line I + 1 describes the land of line I. If all integers are 0 or 1, if it is 1, it indicates that the land is fertile enough. If it is 0, it indicates that the land is not suitable for planting grass.
Output
* Row 1st: an integer is output, that is, the total number of farm distribution solutions divided by the remainder of 100,000,000.
Sample input2 3
1 1 1
0 1 0
Sample output9
Output description:
Number of each block of land:
1 2 3
4
If only one lawn is opened, there are four solutions: Choose one of 1, 2, 3, and 4. There are three solutions for opening up two lawns: 13, 14, and 34. There is only one solution for selecting three lawns: 134. In addition, the total number of solutions is 4 + 3 + 1 + 1 = 9. Hint Source
Gold
Question: naked DP code:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 1314 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define mod 10000000019 using namespace std;20 inline int read()21 {22 int x=0,f=1;char ch=getchar();23 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}24 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}25 return x*f;26 }27 int n,m,f[maxn][1<<maxn];28 int main()29 {30 freopen("input.txt","r",stdin);31 freopen("output.txt","w",stdout);32 n=read();m=read();33 f[0][0]=1;34 for(int i=1;i<=n;i++)35 {36 int x,y=0;37 for(int j=1;j<=m;j++){x=read();if(!x)y+=1<<(j-1);}38 for(int j=0;j<1<<m;j++)39 if(!(j&(j<<1))&&!(j&y))40 for(int k=0;k<1<<m;k++)41 if(!(j&k))42 f[i][j]+=f[i-1][k],f[i][j]%=mod; 43 }44 int ans=0;45 for(int i=0;i<1<<m;i++)ans+=f[n][i],ans%=mod;46 printf("%d\n",ans);47 return 0;48 }
View code
Bzoj1725: [usaco 2006 Nov] corn fields farm Arrangement