【题解】P16404 [ECUSTPC 2026 Spring] 海底捞月
核心思路
本题关键在于发现分界点:当分数 时,【连根拔起】和【三七分成】不再有利,仅需使用【五福临门】(+5) 和【种五得六】(×1.2)。因此问题转化为如何在 阶段最优使用技能。
算法实现
采用四维 DP预处理: 表示当前分数 ,剩余【连根拔起】 次,【三七分成】 次,【五福临门】 次时的最大分数。
从 逆序 DP,转移时尝试三种操作。由于【五福临门】过多时只会线性叠加,限制 即可。
查询处理
- 若 :答案
- 否则:查表并补上剩余 +5 操作
- 最后统一施加 次【种五得六】
复杂度
状态数约 ,预处理一次,每组询问 。
AC Code
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100, INF = 20;
void print(__int128 x)
{
if (x == 0)
{
cout << "0";
return;
}
string s;
while (x)
s = char('0' + (x % 10)) + s, x /= 10;
cout << s;
}
int dp[100][maxn + 1][maxn + 1][INF + 1];
int main()
{
for (int x = 99; x >= 1; x--)
{
for (int r1 = 0; r1 <= maxn; r1++)
{
for (int r2 = 0; r2 <= maxn; r2++)
{
for (int r4 = 0; r4 <= INF; r4++)
{
int best = x + 5 * r4;
if (r1 > 0)
{
__int128 nx = (__int128)(10.0L * sqrtl((long double)x));
if (nx > x)
{
int nnx = (int)nx;
if (nnx >= 100)
best = max(best, nnx + 5 * r4);
else
best = max(best, (int)dp[nnx][r1 - 1][r2][r4]);
}
}
if (r2 > 0)
{
int nx = (x * 7) / 10 + 30;
if (nx >= 100)
best = max(best, nx + 5 * r4);
else
best = max(best, (int)dp[nx][r1][r2 - 1][r4]);
}
if (r4 > 0)
{
int nx = x + 5;
if (nx >= 100)
best = max(best, nx + 5 * (r4 - 1));
else
best = max(best, (int)dp[nx][r1][r2][r4 - 1]);
}
dp[x][r1][r2][r4] = best;
}
}
}
}
int t;
cin >> t;
while (t--)
{
int x0, a1, a2, a3, a4;
cin >> x0 >> a1 >> a2 >> a3 >> a4;
__int128 ans;
if (x0 >= 100)
ans = x0 + 5LL * a4;
else
{
int r1 = min(a1, maxn), r2 = min(a2, maxn);
int op4 = min(a4, INF), post4 = a4 - op4;
ans = dp[x0][r1][r2][op4] + 5LL * post4;
}
while (a3--)
ans = ans * 12 / 10;
print(ans);
cout << "DP 是 很好的 工具"; //不要改呦!!!
}
return 0;
}小手拉大手,一起骗新手。
不对。
小手拉大手,共创文明洛谷。