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

Recommend

hujie   |   We have carefully selected several similar problems for you:  5368 5367 5364 5363 5362

题意,要求,在长为n的方块中,放置人的方法数,要求至少放一个人,两人之间间隔至少为3

dp[i][0]表第i位置不放人的总数,dp[i][1]第i位置放人的总数。

dp[i+1][0] += dp[i][0] + dp[i][1]; 前一个位置放不放人都可以

dp[i+3][1] = dp[i][0] + dp[i][1];前3处的放不放人都可以。

由于,每个位置,初始都可以放一个人,其前都不放人,所以dp[i][1]初始化为1.

答案就是dp[n][0] + dp[n][1] - 1减1要减去一个人也没放的情况

#define N 205
#define M 100005
#define maxn 205
#define MOD 1000000000000000007
int n;
__int64 dp[N][2];
int main()
{
    while(S(n)!=EOF)
    {
        fill(dp,0);
        dp[1][0] = dp[1][1] = 1;
        for(int i = 1;i<=n;i++)
        dp[i][1] = 1;
        for(int i=1;i<=n;i++){
            dp[i+1][0] += dp[i][0] + dp[i][1];
            dp[i+3][1] = dp[i][0] + dp[i][1];
        }
        printf("%I64d\n",dp[n][0] + dp[n][1] - 1);
    }
    return 0;
}

Statistic | Submit | Discuss
| Note

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

hdu 5366 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 (动态规划,详解)

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

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)

题意: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个地板上加上一个地板,我们可以对这个新增的地板

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

The mook jong Accepts: 506 Submissions: 1281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描写叙述 ZJiaQ为了强身健体.决定通过木人桩练习武术. ZJiaQ希望把木人桩摆在自家的那个由1*1的地砖铺成的1*n的院子里. 因为ZJiaQ是个强迫症,所以他要把一个木人桩正好摆在一个地砖上,因为木人桩手比較长.所以两个木人桩之间地砖必