Nudnik Photographer -Ural1260动态规划

If two people were born one after another with one second difference and one of them is a child, then the other one is a child too. We get by induction that all the people are children.
Everyone knows that the mathematical department of the Ural State University is a big family of N persons, 1, 2, 3, …, N years old respectively.
Once the dean of the department ordered a photo if his big family. There were to be present all the students of the department arranged in one row. At first the dean wanted to arrange them by their age starting from the youngest student, but than he decided that it would look unnatural. Than he advised to arrange the students as follows:
The 1 year old student is to sit at the left end of the row.
The difference in ages of every two neighbors mustn’t exceed 2 years.
The dean decided that thereby the students would seem look as they were arranged by their ages (one can hardly see the difference in ages of 25 and 27 years old people). There exist several arrangements satisfying to the requirements. Photographer didn’t want to thwart dean’s desire and made the photos of all the possible mathematical department students’ arrangements.

Input

There is the integer number N, 1 ≤ N ≤ 55.

Output

the number of photos made by the photographer.

Sample

inputoutput
44

Notes

If N = 4 then there are following possible arrangements: (1,2,3,4), (1,2,4,3), (1,3,2,4) and (1,3,4,2).

Problem Author:Alexander Ipatov
Problem Source:Open collegiate programming contest for high school children of the Sverdlovsk region, October 11, 2003

看的我啸的博客

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

typedef long long LL;

LL Dp[60][5];

int main()
{
    Dp[1][1] = 0;
    Dp[1][2] = 1;
    Dp[1][3] = 0;
    Dp[1][4] = 0;

    Dp[2][1] = 0;
    Dp[2][2] = 1;
    Dp[2][3] = 0;
    Dp[2][4] = 0;

    for(int i=3;i<=55;i++)
    {
        Dp[i][1]+=Dp[i-1][2];

        Dp[i][2]+=(Dp[i-1][2]+Dp[i-1][4]);

        Dp[i][3]+=(Dp[i-1][1]+Dp[i-1][3]);

        Dp[i][4]+=(Dp[i-1][1]);
    }
    int n;

    while(~scanf("%d",&n))
    {
        cout<<Dp[n][1]+Dp[n][2]+Dp[n][3]+Dp[n][4]<<endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/juechen/p/5255861.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值