【題解】ZeroJudge c878: 107北二5.議會質詢紀錄

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=c878

#include <iostream>
using namespace std;

int n, mod = 100000007;
long long a[2][3];

int main() {
    cin >> n;
    a[0][0] = 1;
    for (int i = 1; i <= n; i++){
        long long b[2][3] = {};
        b[0][0] = (a[0][0]+a[0][1]+a[0][2]) % mod;
        b[1][0] = (a[0][0]+a[0][1]+a[0][2]+a[1][0]+a[1][1]+a[1][2]) % mod;
        b[0][1] = a[0][0];
        b[1][1] = a[1][0];
        b[0][2] = a[0][1];
        b[1][2] = a[1][1];
        for (int j = 0; j < 2; j++){
            for (int k = 0; k < 3; k++){
                a[j][k] = b[j][k];
            }
        }
    }
    long long tot = 0;
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < 3; j++){
            tot += a[i][j];
            tot %= mod;
        }
    }
    cout << tot << "\n";
}
分享本文 Share with friends