给你三个颜色 红白蓝
让你求在给定条件下n个颜色排列的种类
条件嘛
Stripes of the same color cannot be placed next to each other.
A blue stripe must always be placed between a white and a red or between a red and a white one.
Determine the number of the ways to fulfill his wish.
也就是相同颜色的不能相邻
蓝色相邻的必须是红色和白色(顺序不定
还给了个图,应该是挺好找规律的
----------------------------------------------------我是思路的分割线-----------------------------------------------
因为蓝色不能放在第一个和最后一个(想一想,为什么
那么最后一个和第一个是肯定是红色或白色
然后。。。
。。。。
。。。
我还是直接上图吧。。。。
推到n=5的时候可以明显得到递推公式
dp[i]=dp[i-1]+dp[i-1];
那么问题来了
题目给的范围是1到45,会超int的范围吗?
答案是会的 但是只有45会超。。。。
骗走两个WA。。。。
泪奔ing。。。。。。。。。。。。。。。。
#include<cstdio>
using namespace std;
int main(){
long long dp[46];
dp[0]=0;
dp[1]=2;
for(int i=2;i<46;i++)
dp[i]=dp[i-1]+dp[i-2];
int n;
while(~scanf("%d",&n)){
printf("%lld\n",dp[n]);
}
return 0;
}