擅长排列的小明 II
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
3
-
描述
-
小明十分聪明,而且十分擅长排列计算。
有一天小明心血来潮想考考你,他给了你一个正整数n,序列1,2,3,4,5......n满足以下情况的排列:
1、第一个数必须是1
2、相邻两个数之差不大于2
你的任务是给出排列的种数。
好可怕的规律题,估计再来一遍还是不会吧!!!
如果dp或者其他算法并不能解出的话,就尝试尝试找规律吧。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int book[56]={0,1,1,2};
void init()
{
for(int i=4;i<=55;i++)
{
book[i]=book[i-1]+book[i-3]+1;
}
return ;
}
int main()
{
init();
int n;
while(~scanf("%d",&n))
{
printf("%d\n",book[n]);
}
return 1;
}