Kattis - honey【DP】

题意

有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数

思路

用DP 因为N == 14

所以 最多走7步 我们不妨设 (7, 7) 为原点,然后 dp[0][7][7] = 1

因为 N == 0 的时候 方案数只有一个 那就是 不动吧。。

dp[i][j][k] i 代表第几步 j k 分别表示 目前的位置

一个点 在一张图里面本来有八个方向可以走

这里六边形 我们只取六个方向就可以

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std; typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int dp[30][30][30];
int Move[6][2] =
{
1, 0,
0, 1,
-1, 0,
0,-1,
1, 1,
-1,-1,
};
int main()
{
int i, j, k, l;
memset(dp, 0, sizeof(dp));
dp[0][7][7] = 1;
for (i = 1; i <= 14; i++)
{
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 + Move[l][0]][k + Move[l][1]];
}
}
}
}
int t;
cin >> t;
while (t--)
{
int n;
scanf("%d", &n);
printf("%d\n", dp[n][7][7]);
}
}

Kattis - honey【DP】的更多相关文章

  1. Kattis - virus【字符串】

    Kattis - virus[字符串] 题意 有一个正常的DNA序列,然后被病毒破坏.病毒可以植入一段DNA序列,这段插入DNA序列是可以删除正常DNA序列中的一个连续片段的. 简单来说就是,给你一段 ...

  2. Kattis - fence2【二分法】

    Kattis - fence2[二分法] 题意 有一个农夫需要建造一个 N - 1 米长的篱笆,需要 N 根柱子,然后有 K 根 柱子 需要将这 K 根柱子 切成 N 段 然后 要尽量保证这 N 段柱 ...

  3. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  4. Kattis - cokolada【水】

    Kattis - cokolada[水] 题意 有一个人想吃巧克力,但是巧克力都是按照 2 的幂次的数量包装的,然后他想吃一定数量块的巧克力,然后可以敲碎,每次敲碎都分成两半,比如四块装的分成两块就是 ...

  5. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  6. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  7. HDOJ 1159 Common Subsequence【DP】

    HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  8. HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】

    HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  9. POJ_2533 Longest Ordered Subsequence【DP】【最长上升子序列】

    POJ_2533 Longest Ordered Subsequence[DP][最长递增子序列] Longest Ordered Subsequence Time Limit: 2000MS Mem ...

随机推荐

  1. windows静态库的使用

    最近在学Zeromq(像框架一样的一个socket library)的使用,里面有关于库的使用问题.今天就来复习下静态库的使用: 使用静态库是重用代码的一种绝佳方式.您不必在自己创建的每个程序中重新实 ...

  2. 几种排序算法的java实现

    import java.util.Arrays; /** * 各种排序算法从小到大进行排序 */ public class Test { public static void main(String ...

  3. 【BZOJ】3479: [Usaco2014 Mar]Watering the Fields(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3479 这个还用说吗.... #include <cstdio> #include < ...

  4. Ubuntu14.4下搭配WEB服务器(apache + php + mysql)

    今天,趁着自己动手安装web服务器的余热,将Ubuntu14.4搭配WEB服务器的过程记录下来. “一切皆文件”. 说明:网上关于类似搭配web服务器的教程,案例不计其数,但自己亲自动手“试试”,一定 ...

  5. 【转】CStdioFile UNICODE编译 英文系统下读取中文汉字乱码解决

    转载出处:http://www.cnblogs.com/ct0421/p/3242418.html 函数原形为:char *setlocale( int category, const char *l ...

  6. Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题

    今天在程序中,jedis put数据到redis过程中,“MISCONF Redis is configured to save RDB snapshots, but is currently not ...

  7. python技巧之下划线(二)

    Python 用下划线作为变量前缀和后缀指定特殊变量 _xxx 不能用’from module import *’导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...

  8. web.xml配置文件详解

    笔者从大学毕业一直从事网上银行的开发,都是一些web开发项目.接下来会写一些关于web开发相关的东西,也是自己工作以来经常用到的内容.本篇先从web.xml文件开始介绍,笔者接触到的项目中都有这个文件 ...

  9. std::deque

    deque容器为一个给定类型的元素进行线性处理,像向量一样,它能够快速地随机访问任一个元素,并且能够高效地插入和删除容器的尾部元素.但它又与vector不同,deque支持高效插入和删除容器的头部元素 ...

  10. sql 循环表中记录

    =========================================================================循环排序查询数据=================== ...