Time limit: 1.0 second Memory limit: 64 MB

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

input output
4 4

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

Nudnik Photographer -Ural1260动态规划的更多相关文章

  1. 递推DP URAL 1260 Nudnik Photographer

    题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...

  2. Ural 1260 A nudnik photographer(DP)

    A nudnik photographer 大意: 对1到N这些数进行排列,1必需要在最左边.相邻的两个数之间的差值不能超过2,问有多少种排列的方法. 思路: 对座位进行DP,当第一个是1,第二个是2 ...

  3. Ural 1260 Nudnik Photographer

    Problem Description If two people were born one after another with one second difference and one of ...

  4. URAL 1260 Nudnik Photographer(递推)

    题目链接 题意 : 给你1到n这n个数,排成一排,然后1放在左边最开始,剩下的数进行排列,要求排列出来的数列必须满足任何两个相邻的数之间的差不能超过2,问你有多少种排列 思路 : 对于dp[n], n ...

  5. URAL 1260 Nudnik Photographer DFS DP

    题目:click here :这个题可以先dfs深搜下,规律dp dfs: #include <bits/stdc++.h> using namespace std; #define S ...

  6. URAL(DP集)

    这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include< ...

  7. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  8. 增强学习(三)----- MDP的动态规划解法

    上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...

  9. 简单动态规划-LeetCode198

    题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...

随机推荐

  1. Mysql中实现row_number

    CREATE TABLE `zsl_test` (          `ID` INT(10) NULL DEFAULT NULL,          `class` INT(10) NULL DEF ...

  2. Kafka 解析

    Kafak采用硬盘顺序写入和内存映射文件技术提示性能.即便是顺序写入硬盘,硬盘的访问速度还是不可能追上内存.所以Kafka的数据并不是实时的写入硬盘,它充分利用了现代操作系统分页存储来利用内存提高I/ ...

  3. Hire Me, Microsoft China

    为微软中国工作是一个愿望.对于其他的股票期权,令人难以置信的小吃店或很酷的工作室,引诱他们的可能性.很多人都想为微软中国工作,谁知道,也许你就是其中之一.这个博客是专门为在微软中国工作.做它的工作空缺 ...

  4. LL(1)文法

    <源程序>→<外部声明>|<外部声明><函数体> <外部申明>→<头文件><函数声明>|其他声明 <函数体&g ...

  5. Linux 下应用程序最大打开文件数的理解和修改

    运行在Linux系统上的Java程序运行了一段时间后出现"Too many open files"的异常情况. 这种情况常见于高并发访问文件系统,多线程网络连接等场景.程序经常访问 ...

  6. java中一些定时器的使用

    一:简单说明 ScheduleExecutorService接口中有四个重要的方法,其中scheduleAtFixedRate和scheduleWithFixedDelay在实现定时程序时比较方便. ...

  7. BI实施过程中的工具与服务

    成功的BI项目,不仅仅是应用了BI工具软件,还要具备完善的BI服务体系,才能称之为真正成功的商业智能bi项目. 现在的BI(商业智能)比起几年前的ERP一样,成为CIO们关注的焦点.在ERP等基础信息 ...

  8. Nodes “-1” are listed in ADOP_VALID_NODES table but not in FND_NODES table

    While trying to apply patches to upgrade to 12.2.4, adop failed due to the below errors. Validating ...

  9. mysql slave to master

    1, 在maste A上面创建专门用于备份的用户Bshow master statusget log_file and log_pos 2,CHANGE MASTER TO MASTER_HOST=' ...

  10. RabbitMq中的交换机

          Rabbitmq的核心概念(如下图所示):有虚拟主机.交换机.队列.绑定:                    交换机可以理解成具有路由表的路由程序,仅此而已.每个消息都有一个称为路由键 ...