转移方程推出来的和题解一样,但dp代码不同导致WA
AC
的:
LL s, n, m, a[301][301], dp[30010],ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s >> n >> m;
f(i, 1, s)
{
f(j, 1, n) cin >> a[j][i - 1];
}
f(i, 1, n) sort(a[i], a[i] + s);
for (int k = 1; k <= n; k++)
{
for (int i = m; i >= 0; i--)
{
for (int j = 0; j < s; j++)
{
if(i >=2 * a[k][j] + 1)
dp[i] = max(dp[i], dp[i - 2 * a[k][j] - 1] + k * (j + 1));
}
ans=max(ans,dp[i]);
}
}
cout << ans;
return 0;
}
WA
的:
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s >> n >> m;
f(i, 1, s)
{
f(j, 1, n) cin >> a[j][i - 1];
}
f(i, 1, n) sort(a[i], a[i] + s);
for (int k = 1; k <= n; k++)
{
for (int j = 0; j < s; j++)
{
for (int i = m; i >= 2 * a[k][j] + 1; i--)
{
dp[i] = max(dp[i], dp[i - 2 * a[k][j] - 1] + k );
}
}
}
cout << dp[m];
return 0;
}
update:9.29 8:59
WA
会有重复计算变成完全背包
我是菜鸡