不容易系列之(3)―― LELE的RPG难题

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深Cole终于知道了原因,原来,LELE最近研究起了著名的RPG难题:

有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法.

以上就是著名的RPG难题.

如果你是Cole,我想你一定会想尽办法帮助LELE解决这个问题的;如果不是,看在众多漂亮的痛不欲生的Cole女的面子上,你也不会袖手旁观吧?

 

Input

输入数据包含多个测试实例,每个测试实例占一行,由一个整数N组成,(0<n<=50)。
 

Output

对于每个测试实例,请输出全部的满足要求的涂法,每个实例的输出占一行。
 

Sample Input

1
2
 

Sample Output

3
6
找规律题目 ,用dfs测试一下,很快能发现规律:[n]=f[n-1]+2*f[n-2];
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 
 5 using namespace std;
 6 
 7 int a[2000],n,s;
 8 
 9 /*
10 void dfs(int r)
11 {
12     if(r==n) {s++;return;}
13     if(r!=n-1)
14     {
15         for(int j=1;j<=3;j++)
16             if(j!=a[r-1])
17             {
18                 a[r]=j;
19                 dfs(r+1);
20             }
21     }
22     else if(r==n-1)
23     {
24         for(int j=1;j<=3;j++)
25             if(j!=a[r-1]&&j!=a[0])
26             {
27               a[r]=j;
28               dfs(r+1);
29             }
30     }
31 }
32 */
33 
34 int main()
35 {
36     long long  b[55];
37     b[1]=3,b[2]=6,b[3]=6;
38     for(int i=4;i<=50;i++) b[i]=b[i-1]+2*b[i-2];
39     while(cin>>n)
40     {
41        cout<<b[n]<<endl;
42     }
43 }
原文地址:https://www.cnblogs.com/wsaaaaa/p/4294974.html