1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| #include <bits/stdc++.h> using namespace std;
static long long dp[41][10][10][10];
int main() { int N = 40;
memset(dp, 0, sizeof(dp));
for (int d = 1; d <= 9; d++) { dp[1][d][d][d] = 1; }
for (int pos = 1; pos < N; pos++) { for (int d = 0; d <= 9; d++) { for (int l = 0; l <= 9; l++) { for (int r = l; r <= 9; r++) { long long cur = dp[pos][d][l][r]; if (cur == 0) continue;
if (d - 1 >= 0) { int nd = d - 1; int nl = min(l, nd); int nr = max(r, nd); dp[pos + 1][nd][nl][nr] += cur; } if (d + 1 <= 9) { int nd = d + 1; int nl = min(l, nd); int nr = max(r, nd); dp[pos + 1][nd][nl][nr] += cur; } } } } }
long long ans = 0; for (int pos = 1; pos <= N; pos++) { for (int d = 0; d <= 9; d++) { ans += dp[pos][d][0][9]; } }
cout << ans << "\n";
return 0; }
|