MBEEWALK - Bee Walk

A bee larva living in a hexagonal cell of a large honey comb 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 ?rst 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.

SAMPLE INPUT
2
2
4

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 2^31.

SAMPLE OUTPUT
6
90

dp

/* ***********************************************
Author        :guanjun
Created Time  :2016/10/5 13:32:45
File Name     :spojMBEEWALK.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
    int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
    }
};

bool cmp(int a,int b){
    return a>b;
}
ll dp[50][50][50];
//第i步 到达位置 j k的方案数
int dir[6][2]={
    1,0,-1,0,0,1,0,-1,1,-1,-1,1
};
void init(){
    cle(dp);
    dp[0][15][15]=1;
    for(int i=1;i<=15;i++){
        for(int x=1;x<=30;x++){
            for(int y=1;y<=30;y++){
                for(int j=0;j<6;j++){
                    int nx=x+dir[j][0];
                    int ny=y+dir[j][1];
                        dp[i][x][y]+=dp[i-1][nx][ny];
                }
            }
        }
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int t,n;
    init();
    cin>>t;
    while(t--){
        cin>>n;
        if(n==1)puts("0");
        else{
            cout<<dp[n][15][15]<<endl;
        }
    }
    return 0;
}
A bee larva living in a hexagonal cell of a large honey comb 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 ?rst 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.

SAMPLE INPUT
2
2
4

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 2^31.

SAMPLE OUTPUT
6
90
时间: 2024-10-06 07:35:15

MBEEWALK - Bee Walk的相关文章

BZOJ1695 : [Usaco2007 Demo]Walk the Talk

观察单词表可以发现: 对于长度为3的单词,前两个字母相同的单词不超过7个 对于长度为4的单词,前两个字母相同的单词不超过35个 于是首先$O(26*26*nm)$预处理出 s1[x][i][j]表示(i,j)右上角里面字母x的出现次数 s2[x][y][i][j]表示(i,j)右上角里面单词xy的出现次数 枚举一个点,计算长度为1的单词的出现次数 枚举两个点,计算长度为2,3,4的单词的出现次数 总时间复杂度为$O(kn^2m^2)$,k不超过43 #include<cstdio> #incl

BZOJ 1695 [Usaco2007 Demo]Walk the Talk 链表+数学

题意:链接 方法:乱搞 解析: 出这道题的人存心报复社会. 首先这个单词表-先上网上找这个单词表- 反正总共2265个单词,然后就考虑怎么做就行了. 刚开始我没看表,找不到怎么做,最快的方法我也只是想到了类n^6的做法. 然后我就卡关辣,这关怎么过! 神犇的方法是:观察表,发现规律: 发现表中的单词最长就是4个字母. 所以我们可以考虑求1,2,3,4长度的单词数. 1的话可以直接记录,扫的时候顺带加上就行. 然后神犇说了一句话: 表中长度为4的单词前两个字母相同的单词个数不超过35个. 长度为3

bee使用

beego虽然是一个简单的框架,但是其中用到了很多第三方的包,所以在你安装beego的过程中Go会自动安装其他关联的包. 当然第一步你需要安装Go,如何安装Go请参考我的书 安装beego go get github.com/astaxie/beego 安装bee工具,这个工具可以用来快速的建立beego的应用 go get github.com/beego/bee 这样就完成了beego的安装,你就可以开始开发了,可以通过bee工具来创建beego项目 beego依赖的第三方包有如下: ses

hashlib、walk、yield

一.hashlib 生成MD5值 [[email protected] systeminformation]# vim hashlib2.py  #!/usr/bin/env python import hashlib import sys def md5sum(f):     m = hashlib.md5()     with open(f) as fd:         while True:             data = fd.read(4096)             if 

LYDSY模拟赛day1 Walk

/* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. 时间复杂度 O(20 · 2^20 + n + m) */ #include<cstdio> const int N=1300000,M=700010; int n,m,i,x,y,cnt,g0[N],g1[N],v[M],nxt[M],ed,h,t,q[N],d[N]; void add(in

[py]os.walk爬目录&sys.argv灵活获取参数

1, 遍历目录 os.walk('/tmp') os.next() ? 2,sys.argv ######################################## [email protected]:~/t$ cat t8.py import sys name=sys.argv[1] #获取参数 age=sys.argv[2] ? info=''' name:%s age :%s ''' %(name,age) ? print info print "#"*40 print

python walk函数

os.walk方法 1 import os 2 for i in os.walk(r'C:\Users\jack\Desktop\test\3_语文语文版七年级上册\1_一单元'): 3 print(i[0]) os.walk方法返回的是一个三元tupple(dirpath, dirnames, filenames), 其中第一个为起始路径, 第二个为起始路径下的文件夹, 第三个是起始路径下的文件. dirpath是一个string,代表目录的路径, dirnames是一个list,包含了dir

Python:关于os.path.isdir,os.path.exists,os.walk无法识别“~/&quot; HOME目录的问题。

在编写Python脚本的时候,我发现,os.path.isdir,os.path.exists,os.walk 根本无法识别 ‘~/‘ 表示的HOME目录.例如: Python 2.7.12 (default, Jul 18 2016, 10:55:51) [GCC 6.1.1 20160621 (Red Hat 6.1.1-3)] on linux2 Type "help", "copyright", "credits" or "li

Hdu 5001 Walk 概率dp

Walk Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5001 Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bid