南邮 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] ); } }
相关文章推荐
- UI_UILTView
- 南邮 OJ 1494 Card Trick
- 三证是什么?
- Codeforces Round #Pi (Div. 2) A B
- C#开发winform中OpenFileDialog的运用还可以多选
- 南邮 OJ 1492 Nasty Hacks
- ADB not responding. If you'd like to retry, then please manually kill “adb.exe” and click 'Restart'
- 南邮 OJ 1484 烧饼重叠问题
- NSArray和NSMutableArray
- 南邮 OJ 1469 求和
- typeof() test demo
- LeetCode Single Number II
- 利用Mono.Cecil动态修改程序集来破解商业组件
- LeetCode Single Number II
- 【OC06】类目、延展、协议、计时器(连载八)
- linux挂载光盘,U盘
- 登陆界面的完善
- MVC框架介绍
- 文件目录和库
- JavaScript权威指南_149_第15章_脚本化文档_15.10-其他文档特性-可编辑的内容