标签:des style blog http color 使用 os io
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 1126 | Accepted: 551 |
Description
Input
Output
Sample Input
2 3 -1
Sample Output
2: 0 3: 8
Source
#include<cstdio>
#include<cstring>
#include<iostream>
#define New (1<<(d-1))
using namespace std;
const int maxn=17+10;
long long dp[maxn][5][2][5];
int n;
long long dfs(int ith,int height,int k,int use,int s)
{
if(dp[ith][height][k][use]!=-1)
return dp[ith][height][k][use];
if(ith==n)
{
if(k&&use>=3)
return 1;
else
return 0;
}
long long ans=0;
int tmp;
for(int d=1;d<=4;d++)
{
if(!(s&New))
tmp=use+1;
else
tmp=use;
// tmp=min(use,3);
if(k||(d*height==4&&d!=2))
ans=ans+dfs(ith+1,d,1,tmp,s|New);
else
ans=ans+dfs(ith+1,d,0,tmp,s|New);
}
return dp[ith][height][k][use]=ans;
}
int main()
{
while(~scanf("%d",&n))
{
if(n==-1) return -1;
printf("%d: ",n);
memset(dp,-1,sizeof(dp));
if(n<3)
puts("0");
else
{
dfs(0,0,0,0,0);
printf("%lld\n",dp[0][0][0][0]);
}
}
return 0;
}
poj1351Number of Locks(记忆化搜索),布布扣,bubuko.com
标签:des style blog http color 使用 os io
原文地址:http://blog.csdn.net/u014303647/article/details/38669693