Nudnik Photographer - Ural1260 동적 계획
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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.