URAL 1225(Flags)简单递推
2013-11-13 00:42
316 查看
1225. Flags
Time limit: 1.0 second Memory limit: 64 MBOn the Day of the Flag of Russia a shop-owner decided to decorate the show-window of his shop with textile stripes of white, blue and red colors. He wants to satisfy the following
conditions:
1.Stripes of the same color cannot be placed next to each other.
2.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.
Example.ForN= 3 result is following:
Input
N, the number of the stripes, 1 ≤N≤ 45.Output
M, the number of the ways to decorate the shop-window.Sample
input | output |
---|---|
3 | 4 |
题意:给出红、白、蓝三种颜色;进行涂色;
要求一:相邻的颜色不能相同。要求二:蓝色的两侧颜色不同;
思路:另dp[i]表示当旗帜数为i时合法的方法数,因为当后面加一个红色或者白色气球时,得到的总方法数为dp[i-1],当后面加入蓝色、白色或者蓝色、红色时,总方法数为dp[i-2].
代码如下:
/********************** * author:crazy_石头 * Pro:URAl 1225 * algorithm:dp * Time:0ms * Judge Status:Accepted ***********************/ #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <algorithm> #include <set> #include <vector> #include <cmath> using namespace std; #define rep(i,h,n) for(int i=(h);i<=(n);i++) #define ms(a,b) memset((a),(b),sizeof(a)) #define INF 1<<29 const int maxn=1000+5; long long a[maxn],n; int main() { a[1]=a[2]=2; rep(i,3,45) a[i]=a[i-1]+a[i-2]; while(cin>>n) cout<<a <<endl; return 0; }
相关文章推荐
- timus 1225 flags 基础DP 简单递推
- 递推DP URAL 1225 Flags
- URAL 1225 Flags 简单DP,一重循环
- URAL 1225-Flags(规律递推)
- ural 1225.Flags(简单dp)
- URAL1225——DP——Flags
- Ural_1225 Flags
- Ural 1225 Flags
- URAL 1260 Nudnik Photographer 简单的递推
- ural 1225. Flags
- URAL 1009. K-based Numbers(简单递推)
- Ural_Dynamic Programming Problems_1225-Flags
- URAL 1225. Flags
- URAL-1225 Flags
- Flags-Ural1225简单递推
- URAL 1513. Lemon Tale(简单的递推)
- Flags-Ural1225简单递推
- ural 1225.Flags
- URAL 1225 递推
- ural 1225 Flags