Codeforces 1132E (multiple large data backpack)

Topic Link

The meaning of problems

Backpack given capacity $ w $, respectively, the maximum volume of the volume of the number of objects to $ $ $ 1 $ 8 evaluates the capacity does not exceed the backpack

Thinking

Consider the answer converted to $ 840 * x + y $ form where $ 840 = LCM (1-8), y <840 * 8 $, idea for selected programs in all kinds of articles can be expressed as $ 840 * t_i + form k_i $, then we only consider the case of each item selected to scrape together $ 840 $ enough of those items, if we can be able to get to know the maximum $ 840 $ corresponding to the number of copies selected under these circumstances will be able to get an answer. Therefore $ dp [i] [j] $ represents the front has been completed considering $ i - to get the maximum number of copies $ 840 $ withdrawn $ J $ by weight of the article after 1 $ kinds of goods, the obvious answer is $ max (840 * dp [ 9] [i] + i) $ of course, this is likely to exceed the capacity of the backpack of $ W $, $ W $ and so also compared. 

Code

#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

LL w, cnt[10], dp[10][840 * 8 + 5];

int main() {
    scanf("%lld", &w);
    for(int i = 1; i <= 8; i++) scanf("%lld", &cnt[i]);
    memset(dp, -1, sizeof dp);
    dp[1][0] = 0;
    for(int i = 1; i <= 8; i++) {
        for(int j = 0; j <= 840 * 8; j++) {
            if(dp[i][j] == -1) continue;
            LL t = min(cnt[i], 840LL / i);
            for(int k = 0; k <= t; k++) {
                dp[i + 1][j + k * i] = max(dp[i + 1][j + k * i], dp[i][j] + (cnt[i] - k) / (840 / i));
            }
        }
    }
    LL ans = 0;
    for(int i = 0; i <= 840 * 8; i++) {
        if(i > w || dp[9][i] == -1) continue;
        ans = max(ans, i + min(dp[9][i], (w - i) / 840) * 840);
    }
    cout << ans;
}

  

Guess you like

Origin www.cnblogs.com/DuskOB/p/11184024.html