其他分享
首页 > 其他分享> > Glass Half Spilled

Glass Half Spilled

作者:互联网

Glass Half Spilled

\(dp\)

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define x first
#define y second
#define inf 0x3f3f3f3f
const int N = 110, M = 30010;
int v[N], w[N];
int f[N][N * N];

int main() {
    IO;
    int n;
    cin >> n;
    int sumv = 0, sumw = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i] >> w[i];
        sumv += v[i];
        sumw += w[i];
    }
    
    memset(f, -0x3f, sizeof f);
    f[0][0] = 0;
    for (int i = 1; i <= n; ++i)
        for (int k = i; k >= 1; --k)
            for (int j = sumv; j >= v[i]; --j)
                f[k][j] = max(f[k][j], f[k - 1][j - v[i]] + w[i]);

    for (int k = 1; k <= n; ++k) {
        double ans = 0;
        for (int j = 0; j <= sumv; ++j) ans = max(ans, min(1.0 * j, 0.5 * (sumw + f[k][j])));
        cout << fixed << setprecision(10) << ans << ' ';
    }
    return 0;
}

标签:int,sumv,Spilled,sumw,long,Glass,IO,Half,define
来源: https://www.cnblogs.com/phr2000/p/14433572.html