全 WA,bjd 哪里错了(几周前写的我都快忘了我的思路了 qaq)
#include <bits/stdc++.h>
using namespace std;
struct shelf {
int h, t;
} book[100];
const int inf = 0x3f3f3f3f;
int dp[2][2186][2186];
int roll[100];
bool cmp (shelf x, shelf y) {
return x.h > y.h;
}
int main () {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &book[i].h, &book[i].t);
sort(book + 1, book + n + 1, cmp);
memset(dp, inf, sizeof(dp));
dp[0][0][0] = dp[1][0][0] = 0;
for (int i = 1; i <= n; i++)
roll[i] = roll[i - 1] + book[i].t;
for (int i = 1; i <= n; i++) {
memset(dp[i & 1], inf, sizeof(dp[i & 1]));
for (int j = 0; j <= roll[i]; j++)
for (int k = 0; k <= roll[i]; k++) {
if (i != 0)
dp[i & 1][j + book[i].t][k] = min(dp[i & 1][j + book[i].t][k], dp[(i & 1) ^ 1][j][k]);
else
dp[i & 1][j + book[i].t][k] = min(dp[i & 1][j + book[i].t][k], dp[(i & 1) ^ 1][j][k] + book[i].h);
if (j != 0)
dp[i & 1][j][k + book[i].t] = min(dp[i & 1][j][k + book[i].t], dp[(i & 1) ^ 1][j][k]);
else
dp[i & 1][j][k + book[i].t] = min(dp[i & 1][j][k + book[i].t], dp[(i & 1) ^ 1][j][k] + book[i].h);
if (roll[i - 1] - j - k != 0)
dp[i & 1][j][k] = min(dp[i & 1][j][k], dp[(i & 1) ^ 1][j][k]);
else
dp[i & 1][j][k] = min(dp[i & 1][j][k], dp[(i & 1) ^ 1][j][k] + book[i].h);
}
}
long long ans = inf;
for (int i = 1; i <= roll[n]; i++)
for (int j = 1; j <= roll[n]; j++)
if (roll[n] - i - j > 0)
ans = min(ans, 1ll * max(roll[n] - i - j, max(i, j)) * (1ll * dp[n & 1][i][j]));
printf("%lld", ans / (n - 1) * 10);
return 0;
}