HDU 2045 LELE的RPG难题
递推 枚举起点状态
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][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][0] + dp[i - 1][2], 21 dp[i][2] = dp[i - 1][0] + dp[i - 1][1]; 22 ans += dp[n][1] + dp[n][2]; 23 printf("%lld\n", 3 * ans); 24 } 25 return 0; 26 }