URAL 1225. Flags

给你三个颜色 红白蓝

让你求在给定条件下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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值