HDU--杭电--2323--Honeycomb Walk--DP
来源:互联网 发布:网络鉴黄师招聘 编辑:程序博客网 时间:2024/05/22 15:41
Honeycomb Walk
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 111 Accepted Submission(s): 69
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.
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
题意就是像蜂巢那样的一个点与六个点相邻,从一个点开始走,走了n步之后回到远点的路线数
用三位数组来暴力DP,dp[i][j][k]代表的是走第i步走到坐标为(j,k)的点的方法数
#include <iostream>#include <cstdio>#include <queue>using namespace std;int dp[22][22][22]={0},xx[6][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,-1}};//因为要回原点,所以最远也只会和原点相距14/2的距离,所以取(7,7)为原点(这个原点是随便去的)void DP(){ int i,j,k,l,a,b; dp[0][7][7]=1;//初始化 for(i=1;i<=14;i++)//最多14步 for(j=0;j<=14;j++)//遍历可到的全部坐标点 for(k=0;k<=14;k++) for(l=0;l<6;l++)//遍历相邻的各个方向 dp[i][j][k]+=dp[i-1][j+xx[l][0]][k+xx[l][1]];}int main (void){ int n,m,i,j,k,l; DP(); scanf("%d",&n); while(n--&&scanf("%d",&m)) { printf("%d\n",dp[m][7][7]); } return 0;}
- HDU--杭电--2323--Honeycomb Walk--DP
- hdu 2323 Honeycomb Walk
- POJ 3036 Honeycomb Walk(DP)
- POJ-3036 Honeycomb Walk 简单DP
- poj 3036 Honeycomb Walk 暴力枚举 dp
- 2489. Honeycomb Walk
- Sicily 1415. Honeycomb Walk
- 南邮 OJ 1498 Honeycomb Walk
- 杭电ACM HDU 1142 A Walk Through the Forest
- HDU 杭电5584 LCM Walk【逆推】
- hdu 5001 Walk (概率dp)
- [概率dp] hdu 5001 Walk
- HDU - 5001 Walk(概率dp)
- hdu 5001 Walk ( 概率DP )
- hdu 5001 Walk 概率DP
- HDU Walk (概率DP)
- hdu 5001 Walk 【概率dp】
- HDU 5001 Walk (概率dp)
- php多关键字匹配扩展
- 选择排序----select sort
- cocos2d-x植物大战僵尸(1) (地图的加载)
- 聚餐时学校短暂的回忆
- 保存图片到相册 iphone UIImageWriteToSavedPhotosAlbum 保存图片
- HDU--杭电--2323--Honeycomb Walk--DP
- PE感染-添加节区
- Python一些学习资源
- 8个时刻千万别洗澡 当心惹“病”上身
- Apache Pig的一些基础概念及用法总结(1)
- Ubuntu如何修改计算机名称
- 100个高质量Java开发者博客
- 基于BOA的WEB服务的搭建
- 自己收集的比较好的hadoop博客