您的位置:首页 > 其它

zoj 3466 The Hive II

2012-09-28 10:53 597 查看
小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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  user c