Nudnik Photographer -Ural1260动态规划
2016-02-24 14:18
309 查看
Time limit: 1.0 second | Memory limit: 64 MB |
---|
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 [1]+Dp [2]+Dp [3]+Dp [4]<<endl; } return 0; }
相关文章推荐
- TOMCAT源码导入eclipse
- vim 常用命令
- Javascript中的特殊变量
- 《蒋勋说宋词》 读后感
- jquery的ajax同步和异步
- 理解LinkedHashMap
- Hadoop-1.2.1 Eclipse开发环境配置
- UIBezierPath精讲
- HDU5631(并查集)
- Android之项目全局变量的定义
- PAT (Basic Level)1017. A除以B
- Java动态代理、cglib动态代理
- linux 下 apache启动、停止、重启命令
- 同时启动两个jboss端口提示占用问题
- 对待开源的态度
- freemarker切割字符串长度
- Unity 5.X扩展编辑器之打包assetbundle
- Unity 5.X扩展编辑器之打包assetbundle
- redis服务器初始化化
- java_内部类学习笔记(二)