您的位置:首页 > 其它

南邮 OJ 1498 Honeycomb Walk

2015-08-06 08:35 411 查看


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

;
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]
);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: