poj 2411

题意:用1*2的木板,去覆盖矩阵,求覆盖方法数。

这题是看人家的题解写的,状态的表示有点不一样,横着覆盖就表示成11,竖着的就用上一行为0,下一行为1来表示,这题的关键在于位运算,|和&的用法,特别是判断两行是否和法,除了两行|后要全为1,还要注意,除了竖放的其他木块要合法,刚开始这里错了,simple过不了,后来看人家的代码发现问题。这题还有其他解法,好像有数学方法,还有插头dp,可惜我都不会T_T,有空就研究下。

Run IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time
92253922010307204252411Accepted344K563MSC++944B2011-08-24 23:13:55
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
bool  ac[1<<11];
int n,m,mac;
long long dp[1<<11][11];
bool check(int x)
{
	int count=0;
	while(x)
	{
		if(x&1)count++;
		else 
			{
				if(count&1)
			    return false;
		        else count=0;
		}
		x=x>>1;
	}
	if(count&1)return false;
	return true;
}
bool AC(int x,int y)
{
	if((x|y)!=(1<<n)-1)
		return false;
	else
		return ac[x&y];
}
void DP()
{
	memset(dp,0,sizeof(dp));
	for(int i=0;i<(1<<n);i++)
		if(check(i))
		   ac[i]=dp[i][0]=1;
	for(int i=1;i<m;i++)
		for(int j=0;j<(1<<n);j++)
			for(int k=0;k<(1<<n);k++)
			{
				if(!AC(j,k)) continue;
				//if(dp[k][i-1]==0) continue;
				dp[j][i]+=dp[k][i-1];
			}
			printf("%lld\n",dp[(1<<n)-1][m-1]);
}
int main()
{
	while(1)
	{
		scanf("%d%d",&m,&n);
		if(m==0&&n==0)return 0;
		DP();
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值