HDU 5336 The mook jong (DP)

The mook jong

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 217    Accepted Submission(s): 160

Problem Description

![](../../data/images/C613-1001-1.jpg)

ZJiaQ want to become a strong man, so he decided to play the mook jong。ZJiaQ want to put some mook jongs in his backyard. His backyard consist of n bricks that is 1*1,so it is 1*n。ZJiaQ want to put a mook jong in a brick. because of the hands of the mook jong, the distance of two mook jongs should be equal or more than 2 bricks. Now ZJiaQ want to know how many ways can ZJiaQ put mook jongs legally(at least one mook jong).

Input

There ar multiply cases. For each case, there is a single integer n( 1 < = n < = 60)

Output

Print the ways in a single line for each case.

Sample Input

1

2

3

4

5

6

Sample Output

1

2

3

5

8

12

Source

BestCoder Round #50 (div.2)

题意:ZJiaQ为了强身健体,决定通过木人桩练习武术。ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里。由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两个,现在ZJiaQ想知道在至少摆放一个木人桩的情况下,有多少种摆法。

分析:

1、这道题暴力打表其实可以找出规律

2、用dp来做就是设dp[i][0]表示在第i个格子里面不放木桩,dp[i][1]表示在第i个格子里面放木桩。

如果当前格子放木桩的话:那么dp[i][1]=dp[i-3][0]+dp[i-3][1]

如果当前格子不放木桩的话,那么dp[i][0]=dp[i-1][0]+dp[i-1][1]

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
#define LL __int64
using namespace std;
const int MAXN=60+5;
LL dp[MAXN][2],n;
void init()
{
    dp[1][0]=0;dp[1][1]=1;
    dp[2][0]=1;dp[2][1]=1;
    dp[3][0]=2;dp[3][1]=1;
    for(int i=4;i<=65;i++)
    {
        dp[i][0]=dp[i-1][0]+dp[i-1][1];
        dp[i][1]=dp[i-3][0]+dp[i-3][1]+1;
    }
}

int main()
{
    init();
    //freopen("in.txt","r",stdin);
    while(scanf("%d",&n)!=EOF)
    {
        printf("%I64d\n",dp[n][0]+dp[n][1]);
    }
    return 0;
}

时间: 2024-10-09 12:53:13

HDU 5336 The mook jong (DP)的相关文章

HDU - 5366 The mook jong (dp动态规划)

The mook jong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 62    Accepted Submission(s): 40 Problem Description ![](../../data/images/C613-1001-1.jpg) ZJiaQ want to become a strong man, so h

hdu 5366 The mook jong dp

The mook jong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 263    Accepted Submission(s): 200 Problem Description ![](../../data/images/C613-1001-1.jpg) ZJiaQ want to become a strong man, so

HDU 5366 The mook jong (动态规划,详解)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5366 题面: The mook jong Accepts: 221 Submissions: 306 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description ZJiaQ want to become a strong man, so he decided

HDU 5366 The mook jong

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5366 Problem Description ![](../../data/images/C613-1001-1.jpg) ZJiaQ want to become a strong man, so he decided to play the mook jong.ZJiaQ want to put some mook jongs in his backyard. His backyard con

Hdu 5366 The mook jong 公式求解

The mook jong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 ZJiaQ为了强身健体,决定通过木人桩练习武术.ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里.由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两个,现在ZJiaQ想知道在至少摆放一个木人桩的情况下,有多

HDU5366——The mook jong——dp

The mook jong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 226    Accepted Submission(s): 167 Problem Description ![](../../data/images/C613-1001-1.jpg) ZJiaQ want to become a strong man, so

HDU 5366 The mook jong (简单DP)

题意:ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里.由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两个,现在ZJiaQ想知道在至少摆放一个木人桩的情况下,有多少种摆法. 思路:题意类似于“要求找到所有满足这样要求的二进制的数:(1)不能出现101   (2)不能出现11  (3)不能为0”. 问题是可以降低规模的,也就是也可以递推,假设cnt[i][0]表示第i位放0的所有可能数,cnt[i][1

hdu 5366 The mook jong 动态规划(BC 50 C题)

比赛的时候还是没做出来,BC又是做一题,估计又是要掉分了,慢慢提升,总会终结一题的命运... 思路: 动态规划,然而我刚开始学,并不会做啊...先是找规律找了半天,结果啥也没找出来,又开始深搜, 结果样例能过,交上超时了,深度太大啊,没有正确估算...赛后看了题解,动态规划真是神算法啊,简单几行就 搞定了.设一个数组d[n]表示地板总数(n>3)然后列出状态转移方程d[n] = d[n-1] + (d[n-3] + 1);可以 这样理解,n是在n-1个地板上加上一个地板,我们可以对这个新增的地板

DP BestCoder Round #50 (div.2) 1003 The mook jong

题目传送门 1 /* 2 DP:这题赤裸裸的dp,dp[i][1/0]表示第i块板放木桩和不放木桩的方案数.状态转移方程: 3 dp[i][1] = dp[i-3][1] + dp[i-3][0] + 1; dp[i][0] = dp[i-1][1] + dp[i-1][0]; 4 比赛时二维dp写搓了,主要是边界情况的判断出错,比如dp[3][1] = 1,因为第3块放了木桩,其他地方不能再放,dp[3][0]同理 5 解释一下dp[i][1]的三种情况,可能是前面相隔2个放的方案或者是不放的