您的位置:首页 > 其它

hdu 2323 Honeycomb Walk

2014-08-06 20:09 316 查看
[align=left]Problem Description[/align]
A bee larva living in a hexagonal cell of a large honeycomb decides to creep for a walk. In each “step” the larva may move into any of the six adjacent cells and after n steps, it is to end up in its original
cell.

Your program has to compute, for a given n, the number of different such larva walks.



[align=left]Input[/align]
The first line contains an integer giving the number of test cases to follow. Each case consists of one line containing an integer n, where 1 ≤ n ≤ 14.

[align=left]Output[/align]
For each test case, output one line containing the number of walks. Under the assumption 1 ≤ n ≤ 14, the answer will be less than 231 - 1.

[align=left]Sample Input[/align]

2
2
4


[align=left]Sample Output[/align]

6
90带点搜索意味的dp
#include<iostream>
#include<cstring>
using namespace std;
int dp[17][30][30],p=15,q=15;
int to[6][2]={1,0,-1,0,1,1,0,1,-1,-1,0,-1};
int main()
{
int i,j,k,l,t,n;
memset(dp,0,sizeof dp);
dp[0][p][q]=1;
for(i=1;i<15;i++)
{
for(j=0;j<30;j++)
{
for(k=0;k<30;k++)
{
for(l=0;l<6;l++)
{
int r=j+to[l][0];
int c=k+to[l][1];
dp[i][j][k]+=dp[i-1][r][c];
}
}
}
}
cin>>t;
while(t--)
{
cin>>n;
cout<<dp
[p][q]<<endl;;
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: