zoj 3466 The Hive II

小hh插头dp http://www.notonlysuccess.com/index.php/plug-dp-complete/ 的第二题。

这题比第一题难处理一点,但是方法是一样的,用轮廓线扫一遍就好了,每个可行格子有且仅有两个插头,要分奇偶格子处理



两条轮廓线就像这样,然后层层扫描即可

Run IDSubmit TimeJudge StatusProblem IDLanguageRun Time(ms)Run Memory(KB)User Name
30652402012-09-28 01:02:51Accepted3466C++24702748xym
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<iterator>
#include<stack>
#define LL long long
using namespace std;
int n,m;
int mov[2][4]={1,5,9,13,0,4,8,12};
int num[8]={0,1,1,2,1,2,2,3};
bool gp[10][10];
LL dp[5][1<<16];
char s[10];
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		memset(gp,0,sizeof(gp));
		for(int i=0;i<m;i++)
		{
			scanf("%s",s);
			gp[s[0]-'A'+1][s[1]-'A'+1]=1;
		}
		memset(dp,0,sizeof(dp));
		dp[4][0]=1;
		int sum=1<<16;
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<sum;j++)
			{
				if(j<(1<<15))
					dp[0][j]=dp[4][(j<<1)];
				else dp[0][j]=0;
			}
			for(int j=1;j<=4;j++)
				for(int sta=0;sta<sum;sta++)
					dp[j][sta]=0;
			for(int j=1;j<=4;j++)
			{
				for(int sta=0;sta<sum;sta++)
				{
					int k=(sta>>mov[0][j-1])&7;
					int st1=sta^(k<<mov[0][j-1]);
					if(gp[i][j*2])
					{
						if(k==0)
							dp[j][sta]=dp[j-1][sta];
						continue;
					}
					else
					{
						for(int x=0;x<8;x++)
						{
							if(num[k]+num[x]==2)
							{
								dp[j][sta]+=dp[j-1][st1^(x<<mov[0][j-1])];
							}
						}
					}
				}
			}
			for(int j=0;j<sum;j++)
				dp[0][j]=0;
			for(int j=0;j<sum;j++)
			{
				if(j<(1<<15))
					dp[0][j<<1]=dp[4][j];
			}
			for(int j=1;j<=4;j++)
				for(int sta=0;sta<sum;sta++)
					dp[j][sta]=0;
			for(int j=1;j<=4;j++)
			{
				for(int sta=0;sta<sum;sta++)
				{
					int k=(sta>>mov[1][j-1])&7;
					int st1=(sta^(k<<mov[1][j-1]));
					if(gp[i][j*2-1])
					{
						if(k==0)
							dp[j][sta]=dp[j-1][sta];
						continue;
					}
					else
					{
						for(int x=0;x<8;x++)
						{
							if(num[k]+num[x]==2)
							{
								dp[j][sta]+=dp[j-1][st1^(x<<mov[1][j-1])];
							}
						}
					}
				}
			}
		}
		cout<<dp[4][0]<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值