南邮 OJ 1498 Honeycomb Walk

Honeycomb Walk

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 34            测试通过 : 14 

比赛描述

    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.



输入

    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.

输出

    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.

样例输入

2
2
4

样例输出

6
90

题目来源

Nordic 2006




//dp[i][j][k] = 第 k 步走到(i,j)的走法
#include<iostream>
#define N 15
int dp[N][N][N];
int dirX[6] = { 1, 0,-1,-1, 0, 1};
int dirY[6] = { 0, 1, 1, 0,-1,-1};

int main(){
	int i,j,k,d,x,y;
	dp[7][7][0] = 1;
	for(k=1;k<N;k++){
		for(i=0;i<N;i++){
			for(j=0;j<N;j++){
				for(d=0;d<6;d++){
					x = i+dirX[d];
					y = j+dirY[d];
					if(x>=0 && x<N && y>=0 && y<N){
						dp[i][j][k] += dp[x][y][k-1];
					}
				}
			}
		}
	}
	int t,n;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		printf("%d\n",dp[7][7][n]);
	}
}






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值