BZOJ 2331 SCOI2011 地板 插头DP

题目大意:给定一张有坏点的地图,要求用L型地毯将整个图覆盖,求方案数

插头DP。。。

首先由于R*C<=100,故min(R,C)<=10

然后插头状态为:0-无插头 1-有一个没有拐过的插头 2-有一个拐过的插头

然后就自己YY吧。。。。

珍爱生命,远离memset

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 110
#define MOD 20110520
using namespace std;
int m,n;
char s[M][M];
int sta[200200],tot;
bool Available(int temp)
{
	int i;
	for(i=1;i<=n+1;i++)
	{
		if( (temp&3)==3 )
			return false;
		temp>>=2;
	}
	return true;
}
struct Hash_Table{
	struct List{
		int hash,val;
		List *next;
		List(int _,List *__):
			hash(_),val(0),next(__) {}
	}*head[200199];
	int& operator [] (int x)
	{
		int pos=x%200199;
		List *temp;
		for(temp=head[pos];temp;temp=temp->next)
			if(temp->hash==x)
				return temp->val;
		return (head[pos]=new List(x,head[pos]))->val;
	}
	bool Find(int x)
	{
		int pos=x%200199;
		List *temp;
		for(temp=head[pos];temp;temp=temp->next)
			if(temp->hash==x)
				return true;
		return false;
	}
}f,g;
int main()
{
	int i,j,k;
	cin>>m>>n;
	for(i=1;i<=m;i++)
		scanf("%s",s[i]+1);
	if(m<n)
	{
		swap(m,n);
		static char temp[M][M];
		for(i=1;i<=m;i++)
			for(j=1;j<=n;j++)
				temp[i][j]=s[j][i];
		memcpy(s,temp,sizeof s);
	}
	for(i=0;i<1<<(n+1)*2;i++)
		if(Available(i))
			sta[++tot]=i;
	f[0]=1;
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			memset(&g,0,sizeof g);
			for(k=1;k<=tot;k++)
			{
				int sta=::sta[k];
				if(!f.Find(sta))
					continue;
				if(s[i][j]=='*')
				{
					if( ((sta>>(n-j)*2)&15)==0 )
						(g[sta]+=f[sta])%=MOD;
				}
				else
				{
					switch( (sta>>(n-j)*2)&15 )
					{
						case 0:
							(g[sta^(0<<(n-j)*2)^(1<<(n-j)*2)]+=f[sta])%=MOD;
							(g[sta^(0<<(n-j)*2)^(4<<(n-j)*2)]+=f[sta])%=MOD;
							(g[sta^(0<<(n-j)*2)^(10<<(n-j)*2)]+=f[sta])%=MOD;
							break;
						case 1:
							(g[sta^(1<<(n-j)*2)^(4<<(n-j)*2)]+=f[sta])%=MOD;
							(g[sta^(1<<(n-j)*2)^(2<<(n-j)*2)]+=f[sta])%=MOD;
							break;
						case 2:
							(g[sta^(2<<(n-j)*2)^(8<<(n-j)*2)]+=f[sta])%=MOD;
							(g[sta^(2<<(n-j)*2)^(0<<(n-j)*2)]+=f[sta])%=MOD;
							break;
						case 4:
							(g[sta^(4<<(n-j)*2)^(8<<(n-j)*2)]+=f[sta])%=MOD;
							(g[sta^(4<<(n-j)*2)^(1<<(n-j)*2)]+=f[sta])%=MOD;
							break;
						case 5:
							(g[sta^(5<<(n-j)*2)^(0<<(n-j)*2)]+=f[sta])%=MOD;
							break;
						case 8:
							(g[sta^(8<<(n-j)*2)^(0<<(n-j)*2)]+=f[sta])%=MOD;
							(g[sta^(8<<(n-j)*2)^(2<<(n-j)*2)]+=f[sta])%=MOD;
							break;
					}
				}
			}
			memcpy(&f,&g,sizeof f);
		}
		memset(&g,0,sizeof g);
		for(k=1;k<=tot;k++)
		{
			int sta=::sta[k];
			if(!f.Find(sta))
				continue;
			if( (sta&3)==0 )
				g[sta>>2]=f[sta];
		}
		memcpy(&f,&g,sizeof f);
	}
	cout<<f[0]<<endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值