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. EntityFramework 连接字符串

    1. Microsoft SQL Server 2016 LocalDB <connectionStrings> <add name="DefaultConnection& ...

  2. python thrift 服务端与客户端使用

    一.简介 thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, Erlang, ...

  3. .NET对象与Windows句柄(一):句柄的基本概念

    在.NET编程中,得益于有效的内存管理机制,对象的创建和使用比较方便,大多数情况下我们无须关心对象创建和分配内存的细节,也可以放心的把对象的清理交给自动垃圾回收来完成.由于.NET类库对系统底层对象进 ...

  4. List与Json的相互转换

    List 与 Json 的相互转换,需要使用到6个jar包,如果不引用这些jar包,需要写的代码量比较多,这里暂时记录的是使用jar包来进行转换的情况. 下面图片是测试demo的结构,仅供参考,需要注 ...

  5. css中很有用的属性

    有些css属性很实用,但不常用也就被忘记. 这里纪录了自己在项目中用过的一些. html,body{ -webkit-tap-highlight-color:transparent; } 这个的用途是 ...

  6. Linux TOP命令 按内存占用排序和按CPU占用排序

    P – 以 CPU 占用率大小的顺序排列进程列表M – 以内存占用率大小的顺序排列进程列表 http://blog.csdn.net/xiliuhu/article/details/6449377

  7. [Python笔记]序列(一)索引、分片

    Python包含6种内建序列:列表.元组.字符串.Unicode字符串.buffer对象.xrange对象. 这些序列支持通用的操作: 索引 索引是从0开始计数:当索引值为负数时,表示从最后一个元素( ...

  8. web app上传图片

    很就很久以前,web app上传图片需要通过cordova插件,那时候好像还叫phonegap. 后来一个html标签就可以了 <input type="file" clas ...

  9. ko trick

    (1)let a = ko.observable(‘A’)绑定到select,如果下拉列表中找不到'A', 变量a会赋值成undefined.   要解决此问题可以使用绑定valueAllowUnse ...

  10. R12.2.6 installation failed with - Unable to rename database

    报错信息: 日志信息:/data/ebsdb/VIS/12.1.0/appsutil/log/VIS_ebstest/12222150.log Phase 3 Rename Database Exec ...