计蒜客 墙壁涂色

题目:

https://www.jisuanke.com/course/2291/182250

思路:

来自https://blog.csdn.net/a1097304791/article/details/81191256

递推,画图得type[1]=3,type[2]=6,type[3]=6,n从4开始,

①当第1项和第n-1项不同色时。第n项只有一种颜色可以取,即type[n]=typef[n-1]
②当第1项和第n-1项同色时。第n项有两种颜色可以取,同时因为第n块和第n-1块不同色,所以type[n]=2*type[n-2]
相加得type[n] =type[n-1] + type[n-2]*2  

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 
 8 int  n;
 9 long long type[55];
10  
11 void work()
12 {
13     type[1]=3;
14     type[2]=6;
15     type[3]=6;
16     for(int i=4;i<=50;i++)
17     {
18         type[i]=type[i-2]*2+type[i-1];
19     }
20 }
21 
22 int main()
23 {
24     work();
25     while(scanf("%d",&n)==1)
26     {
27         printf("%lld\n",type[n]);
28     }
29     return 0;
30 }

 

posted @ 2019-03-29 21:42  付玬熙  阅读(217)  评论(0编辑  收藏  举报