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

你可能感兴趣的:(hdu 5366 The mook jong dp)