mpfeitech7416
212 天前
private static int minDaysToCollect100Pokemons() {
int[][] dp = new int[101][6];
for (int[] row : dp) {
Arrays.fill(row, INF);
}
// 初始化状态
dp[0][3] = dp[0][4] = dp[0][5] = 0;
// 填充 DP 表
for (int i = 0; i <= 100; i++) {
for (int last : new int[]{3, 4, 5}) {
if (dp[i][last] != INF) {
if (i + 3 <= 100 && last != 3) {
dp[i + 3][3] = Math.min(dp[i + 3][3], dp[i][last] + 1);
}
if (i + 4 <= 100 && last != 4) {
dp[i + 4][4] = Math.min(dp[i + 4][4], dp[i][last] + 1);
}
if (i + 5 <= 100 && last != 5) {
dp[i + 5][5] = Math.min(dp[i + 5][5], dp[i][last] + 1);
}
}
}
}
return Math.min(dp[100][3], Math.min(dp[100][4], dp[100][5]));
}