Nudnik Photographer -Ural1260动态规划
| 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动态规划的更多相关文章
- 递推DP URAL 1260 Nudnik Photographer
题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...
- Ural 1260 A nudnik photographer(DP)
A nudnik photographer 大意: 对1到N这些数进行排列,1必需要在最左边.相邻的两个数之间的差值不能超过2,问有多少种排列的方法. 思路: 对座位进行DP,当第一个是1,第二个是2 ...
- Ural 1260 Nudnik Photographer
Problem Description If two people were born one after another with one second difference and one of ...
- URAL 1260 Nudnik Photographer(递推)
题目链接 题意 : 给你1到n这n个数,排成一排,然后1放在左边最开始,剩下的数进行排列,要求排列出来的数列必须满足任何两个相邻的数之间的差不能超过2,问你有多少种排列 思路 : 对于dp[n], n ...
- URAL 1260 Nudnik Photographer DFS DP
题目:click here :这个题可以先dfs深搜下,规律dp dfs: #include <bits/stdc++.h> using namespace std; #define S ...
- URAL(DP集)
这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include< ...
- URAL DP第一发
列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...
- 增强学习(三)----- MDP的动态规划解法
上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...
- 简单动态规划-LeetCode198
题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...
随机推荐
- Week 1:2015/4/27~2015/5/3
Update everyday.(Last edit:4/30 01:00) Task 1:TPO X 2.5(finish 1,then finish 2 more) Task 2:TC Tarja ...
- Mysql中实现row_number
CREATE TABLE `zsl_test` ( `ID` INT(10) NULL DEFAULT NULL, `class` INT(10) NULL DEF ...
- JPA 2.1 Coverter 注解
@Converter(autoApply = true) public class VehicleConverter implements AttributeConverter<Vehicle, ...
- 利用paramiko模块实现堡垒机+审计功能
paramiko模块是一个远程连接服务器,全真模拟ssh2协议的python模块,借助paramiko源码包中的demos目录下:demo.py和interactive.py两个模块实现简单的堡垒机+ ...
- 阻止网页内部滚动条mousewheel事件冒泡
function preventScroll(id){ var _this = document.getElementById(id); if(navigator.userAgent.indexOf( ...
- java环境变量的设置
java安装好后需要配置一下环境变量,配置方法如下: 1.在系统变量里添加两条记录: 1)变量名:JAVA_HOME,变量值为java安装路径,如:C:\Program Files\Java\jdk1 ...
- CDN技术详解
CDN,全称为Content DeliveryNetwork,中文意为"内容分发网络"".通过将网络内容发布到最靠近用户的『边缘节点』,使不同地区的用户在访问相同页面.图 ...
- 分析App应用市场, App应用有哪些类型
随着移动互联网的流行,APP应用也是异常火爆,App应用市场就如破冰的泉水在我们的生活中到处渗透,对于App开发的的状况来分析,企业在寻找技术人员开发一款专业的App软件的时候,必须先了解用户的需求与 ...
- MWeb 1.5 发布!增加打字机滚动模式、发布到 Evernote、印象笔记、Wordpress.com、Blogger、编辑器内代码块语法高亮
打字机滚动模式(Typewriter Scrolling) 快捷键:CMD + Option + T,菜单:View - Typewriter Scrolling ,效果如下图: 发布到 Everno ...
- Linux:krb5
Kerberos协议主要用于计算机网络的身份鉴别(Authentication), 其特点是用户只需输入一次身份验证信息就可以凭借此验证获得的票据(ticket-granting ticket)访问多 ...