hdu 2323 Honeycomb Walk

来源:互联网 发布:卫生间js防水技术交底 编辑:程序博客网 时间:2024/06/06 03:34
Problem Description
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.
 
Input
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.

Output
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.
 
Sample Input
224

Sample Output
690
带点搜索意味的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[n][p][q]<<endl;;    }    return 0;}


0 0
原创粉丝点击