码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5366 The mook jong

时间:2016-02-21 18:39:09      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

Problem Description

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 are 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*n的院子里铺有1*1的地板,在地板上里放置木人桩,木人桩之间至少相隔2快地板,问至少放置一个木人桩的情况下,可能的情况
 
题解
 
不妨设从右往左摆放,在摆放的过程中,显然,对于尚未摆放的部分,只有已摆放的最左的那个木桩有影响,命名为“哨兵桩”,其余已摆放的木桩的摆放情况没有影响
为了便于解释,不妨从左往右编号方格为1-n,这种情况下,哨兵桩位置为i时,接下来只有i-3,i-4……1这些位置可以摆放或者不摆
所以,设a[i]为哨兵桩在i时接下来的摆放方案数,显然a[i]=a[i-3]+a[i-4]+……+a[1]+1;
而最后的答案应该是ans[i]=a[1]+a[2]+……+a[i];
初始时,a[1]=1;a[2]=1;a[3]=1;
 
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;

LL a[70];
LL ans[70];

int main(void)
{
    int n;
    
    a[1]=1;a[2]=1;a[3]=1;
    ans[1]=1;ans[2]=2;ans[3]=3;
    LL sum=0;
    for (int i=4;i<=60;++i)
    {
        sum+=a[i-3];
        a[i]=sum+1;
        ans[i]=ans[i-1]+a[i];
    }
    
    while (scanf("%d",&n)!=EOF)
    {
        cout<<ans[n]<<endl;
    }
    
}

 

 

HDU 5366 The mook jong

标签:

原文地址:http://www.cnblogs.com/123-123/p/5189413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!