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. SecureCRT超级终端使用说明

    SecureCRT超级终端使用说明 一.连接POS机 1.运行SecureCRT,选择‘文件’菜单,在下拉菜单中选择‘快速连接’菜单: 2.在弹出的对话框中按如下图选择参数: 3.POS端开机,且数据 ...

  2. 【转】msxml 操作xml

    转自http://blog.csdn.net/dai_jing/article/details/8393392,原始出处不详. 1.简介 在.NET平台,微软为C#或托管C++程序员提供了丰富的类库, ...

  3. ubuntu终端使用代理

    sudo http_proxy=http://your_proxy:proxy_port dropbox start -i or sudo https_proxy=http://your_proxy: ...

  4. MathType与Origin是怎么兼容的

    MathType作为一款常用的公式编辑器,可以与很多的软件兼容使用.Origin虽然是一款专业绘图与数据分析软件,但是在使用过程中也是可以用到MathType.它可以帮助Origin给图表加上标签,或 ...

  5. Python创建数组

    1  创建数组 array函数 >>> a=([1,2],[3,4]) >>> array(a) array([[1, 2], [3, 4]]) arange函数: ...

  6. [Algorithms] Longest Common Subsequence

    The Longest Common Subsequence (LCS) problem is as follows: Given two sequences s and t, find the le ...

  7. 160704、commons-beanutils.jar常用方法

    package com.test.beanutils; import java.lang.reflect.InvocationTargetException;import java.text.Pars ...

  8. 关于 Intellij IDEA Ultimate Edition 14.1控制台中文乱码 解决

    经过尝试,我发现,乱码主要是跟控制台右下角的编码有关  如下图 当然IDE Encoding 和 Project Encoding 你可以都设置位UTF-8 或者都设置为GBK    如下图:

  9. 巨蟒python全栈开发数据库攻略2:基础攻略2

    1.存储引擎表类型 2.整数类型和sql_mode 3.浮点类&字符串类型&日期类型&集合类型&枚举类型 4.数值类型补充 5.完整性约束

  10. showslow / YSlow for PhantomJS/slimerjs(gecko)/phantomas

    http://yslow.org/phantomjs/ http://www.bstester.com/2015/12/front-end-performance-using-jenkinsphant ...