水到不想整理,线性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 }

 

相关文章:

  • 2021-11-20
  • 2021-09-16
  • 2021-07-02
  • 2021-08-23
  • 2022-12-23
  • 2021-12-06
  • 2021-09-21
  • 2021-05-03
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2021-10-12
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案