AC

许诺  •  1个月前


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std; int main() {

int n, m;
cin >> n >> m;
vector<int> dp(m + 1, 0);
for (int i = 0; i < n; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
        int A, B;
        cin >> A >> B;
        for (int j = m; j >= 0; --j) {
            for (int x = 1; x <= j; ++x) {
                int value = A * x * x - B * x;
                if (value > 0 && dp[j - x] + value > dp[j]) {
                    dp[j] = dp[j - x] + value;
                }
            }
        }
    } else if (type == 2) {
        int A, B, C;
        cin >> A >> B >> C;
        int k = 1;
        while (k <= C) {
            int value = k * A;
            int volume = k * B;
            for (int j = m; j >= volume; --j) {
                if (dp[j - volume] + value > dp[j]) {
                    dp[j] = dp[j - volume] + value;
                }
            }
            C -= k;
            k *= 2;
        }
        if (C > 0) {
            int value = C * A;
            int volume = C * B;
            for (int j = m; j >= volume; --j) {
                if (dp[j - volume] + value > dp[j]) {
                    dp[j] = dp[j - volume] + value;
                }
            }
        }
    } else if (type == 3) {
        int A, B;
        cin >> A >> B;
        for (int j = B; j <= m; ++j) {
            if (dp[j - B] + A > dp[j]) {
                dp[j] = dp[j - B] + A;
            }
        }
    }
}
cout << dp[m] << endl;
return 0;

}


评论:

请先登录,才能进行评论