HDU 2323 Honeycomb Walk

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
2
2
4
Sample Output
6
90
分析:

可以把每个六边形抽象成一个点,然后再进一步抽象成一个坐标平面。这样的话,一个状态就可以用到达这一状态所用的步数k,这一状态所在的x坐标,y坐标来表示。状态的目标函数自然就是到达这一状态可能的路径数。接下来,就是状态转移方程了。

Way[k][i][j]=way[k-1][i][j+1]+way[k-1][i][j-1]+way[k-1][i-1][j]

+way[k-1][i-1][j-1]+way[k-1][i+1][j] +way[k-1][i+1][j+1]

循环时,首先是k,然后i,j

code:
View Code
#include<stdio.h>
int way[15][17][17];
int list[15];
int main()
{
int k,n,i,j,t;
way[0][8][8]=1;
for(k=1;k<=14;k++)
{
for(i=0;i<17;i++)
for(j=1;j<17;j++)
way[k][i][j]=way[k-1][i-1][j]+way[k-1][i][j+1]
+way[k-1][i+1][j]+way[k-1][i+1][j+1]
+way[k-1][i][j-1]+way[k-1][i-1][j-1];
list[k]=way[k][8][8];
}
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d\n",list[n]);
}
return 0;
}

 

转载于:https://www.cnblogs.com/dream-wind/archive/2012/03/14/2396320.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值