HDU 2047 EOF牛肉串
阿新 • • 發佈:2018-12-13
水到不想整理,線性DP
1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 6 using namespace std; 7 8 long long n, dp[55][3], ans = 0; 9 10 int main() 11 { 12 while (~scanf("%d", &n)) 13 { 14 ans = 0; 15 if(n == 1) { puts("3"); continue; } 16 memset(dp, 0, sizeof(dp)); 17 dp[1][1] = dp[1][2] = dp[1][0] = 1; 18 for (int i = 2; i <= n; ++i) 19 dp[i][0] = dp[i - 1][1] + dp[i - 1][2], 20 dp[i][1] = dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][0], 21 dp[i][2] = dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]; 22 printf("%lld\n", dp[n][0] + dp[n][1] + dp[n][2]); 23 } 24 return 0; 25 }