codeforces 166e Tetrahedron 水dp

来源:互联网 发布:30岁的程序员何去何从 编辑:程序博客网 时间:2024/04/28 18:02

题意:

思路:

定义dp[i][x]:走了i步,刚好走到x的种数。

转移:把另外三个位置的种数累加到当前位置上。

code:

#include <bits/stdc++.h>using namespace std;const int MAXN = 1e7+5;const int MOD = 1e9+7;int dp[MAXN][5];inline void add(int &a, int b) {    a = a+b;    if(a >= MOD) a -= MOD;}int main() {    int n;    cin>>n;    memset(dp, 0, sizeof(dp));    dp[0][0] = 1;    for(int i = 1;i <= n; i++) {        for(int j = 0;j < 4; j++) {            for(int z = 0;z < 4; z++) {                if(j == z) continue;                add(dp[i][j], dp[i-1][z]);            }        }    }    cout<<dp[n][0]<<endl;    return 0;}


0 0
原创粉丝点击