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 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

题目大意:在由1*1的地砖铺成的1*n的院子里摆放木桩,每个木桩放在一个地板上。每两个木桩之间间隔至少两个地板,问有多少种放法。

解题思路:比赛的时候用的搜索,那叫一个慢,就打了40——60之间的表,算是蒙混过关。但是其实正解是dp。对于某个地板,可以放或者不放,那么如果放的话,结果加上dp[i-3]。如果不放的话,dp[i-1]是最优子结构,同时加上一共只放一个木桩在i位置的情况。dp[i]=dp[i-3]+dp[i-1]+1。结果超int需注意。

#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
INT dp[65];
int main(){
    dp[1]=1,dp[2]=2,dp[3]=3;
    for(int i=4;i<=62;i++)
        dp[i]=dp[i-3]+dp[i-1]+1;
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%lld\n",dp[n]);
    }
    return 0;
}

  

时间: 2024-10-30 14:28:11

HDU5366——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 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

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

hdu5366 The mook jong

题目链接:点击打开链接 问题描述 ZJiaQ为了强身健体,决定通过木人桩练习武术.ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里.由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两个,现在ZJiaQ想知道在至少摆放一个木人桩的情况下,有多少种摆法. 输入描述 输入有多组数据,每组数据第一行为一个整数n(1 < = n < = 60) 输出描述 对于每组数据输出一行表示摆放方案数 解题思路:动态规划(

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个放的方案或者是不放的

The mook jong 计数DP

The mook jong ZJiaQ为了强身健体,决定通过木人桩练习武术.ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里.由于ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,由于木人桩手比较长,所以两个木人桩之间地砖必须大于等于两个,现在ZJiaQ想知道在至少摆放一个木人桩的情况下,有多少种摆法. 输入描述 输入有多组数据,每组数据第一行为一个整数n(1 < = n < = 60) 输出描述 对于每组数据输出一行表示摆放方案数 1 #include &l

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想知道在至少摆放一个木人桩的情况下,有多

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