HDU 2045

HDU 2045

思路

假设第 \(n\) 个格子与第一个格子不同色,与第\(n-1\)个格子同色,则只能填一种颜色,\(f[n-1]*1\)

假设第\(n -1\) 个格子与第一个格子同色,则第\(n\) 个格子可以填两种颜色,\(f[n-2]*1*2\)

\(f[n]=2f[n-2]+f[n-1]\)

#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef long long LL;
LL f[N] = {0,3,6,6},k = 3;
int main() {
    int n;
    while(cin >> n) {
        if(n > k) {
            while(k <= n) {
                k ++;
                f[k] = 2*f[k - 2] + f[k - 1];
            }
        }
        cout << f[n] << endl;
    }
    return 0;
}
posted @ 2020-02-13 01:48  lukelmouse  阅读(95)  评论(0编辑  收藏  举报