Codeforces 1132E (看题解)

时间:2023-03-09 15:29:44
Codeforces 1132E (看题解)

感觉这个题挺有意思的, 我们可以将 L = lcm(1, 2, 3, ... , 8) 看作一组。

然后用dp[ i ][ j ]表示到第 i 种物品当前的值为 j 能用L的最大数量。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); LL W, c[];
LL dp[][ * + ]; int main() {
scanf("%lld", &W);
for(int i = ; i <= ; i++) scanf("%lld", &c[i]);
memset(dp, -, sizeof(dp));
dp[][] = ;
for(int i = ; i <= ; i++) {
for(int j = ; j <= * ; j++) {
if(~dp[i][j]) {
LL up = / (i + );
up = min(up, c[i + ]);
for(int k = ; k <= up; k++) {
dp[i + ][j + k * (i + )] = max(dp[i + ][j + k * (i + )], dp[i][j] + (c[i + ] - k) / ( / (i + )));
}
}
}
}
LL ans = ;
for(int i = ; i <= * ; i++) {
if(i <= W && ~dp[][i]) {
ans = max(ans, i + * (min(dp[][i], (W - i) / )));
}
}
printf("%lld\n", ans);
return ;
} /*
*/