前言:一开始我根本想不到这个题目是一个动态规划的题目,而且我一开始的初始状态还写错了
我还忘记了写算法题的基本步骤,先看数据范围,再考虑能不能用动态规划写
题目地址
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (int)35;
int dp[N][N * 4];
int n;
signed main() {
cin >> n;
//for (int i = 0; i <= n * 4; i++) dp[0][i] = 1;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = i * 4; j; j--) {
for (int k = 1; k <= 4; k++) {
if (k > j) continue;
dp[i][j] += dp[i - 1][j - k];
}
}
}
int ans = 0;
for (int i = 3 * n; i <= 4 * n; i++) ans += dp[n][i];
int u = pow(4, n);
int d = __gcd(ans,u);
//cout << ans << " " << u << endl;
cout << ans / d << "/" << u / d;
return 0;
}