Corn Fields POJ - 3254

Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.

Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.

Input

Line 1: Two space-separated integers: M and N 
Lines 2.. M+1: Line i+1 describes row i of the pasture with N space-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)

Output

Line 1: One integer: the number of ways that FJ can choose the squares modulo 100,000,000.

Sample Input

2 3
1 1 1
0 1 0

Sample Output

9

Hint

Number the squares as follows: 

1 2 3
  4  


There are four ways to plant only on one squares (1, 2, 3, or 4), three ways to plant on two squares (13, 14, or 34), 1 way to plant on three squares (134), and one way to plant on no squares. 4+3+1+1=9.

相较于炮兵阵地还是没那么六 毕竟简单题

同样 枚举状态放在s数组里面

还有要说的都在注释里面了

 

#include<cstdio>
#include<algorithm>
#include<cstring>
#define mod 1000000000
#define clr(a,b) memset(a,b,sizeof(a));
#include<iostream>
using namespace std;

int maxn=0;
int dp[20][1000];
int cur[20];
int land[20];
int s[1000];
int m,n;

void init()
{
	maxn=0;
	for(int i=0;i<(1<<n);i++)
	{
		if((i&(i<<1))==0) s[++maxn]=i; 
		
	}
} 

int main()
{
	while(scanf("%d%d",&m,&n)!=EOF)
	{
		init();
		//printf("%d\n",maxn);
		clr(land,0)
		clr(dp,0)
		int temp=0;
		//printf("stop");
		for(int i=1;i<=m;i++)
		{
			//printf("stop");
			for(int j=1;j<=n;j++)
			{
				scanf("%d",&temp);
				if(temp==0) land[i]=land[i]|(1<<(n-j));//不能放的存为1 这样用land[i] 和状态s按位与一下 出现1就可以表示不合法辣
			}
		}
		//cout<<land[1]<<land[2]<<endl;
		for(int i=1;i<=maxn;i++)
		{
			if((land[1]&s[i])==0)
			dp[1][i]=1;
		}
		
		for(int i=2;i<=m;i++)
		{
			for(int j=1;j<=maxn;j++)
			{
				if((land[i]&s[j])==0) //s[j]合法
				for(int k=1;k<=maxn;k++)//枚举上一层状态
				{
					if((land[i-1]&s[k])==0&&(s[k]&s[j])==0) //s[k]合法  
					dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;//求方法总数 所以相加
				}
			}
		}
		int ans=0;
		for(int i=1;i<=maxn;i++)
		{
			ans=(ans+dp[m][i])%mod;
		}	
		printf("%d\n",ans);
	}
}

 

CCF大数据与计算智能大赛-面向电信行业存量用户的智能套餐个性化匹配模型联通赛-复赛第二名-【多分类,embedding】.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值