6 条题解

  • 0
    @ 2026-4-26 20:07:28
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e5 + 10;
    int m, n;
    int w[N], c[N], len;
    int dp[N], x, y, z;
    int main(){
    	cin >> n >> m;
    	for(int i = 1 ; i <= n ; i++){
    		cin >> x >> y >> z;
    		if(z == -1) z = 1;
    		if(z == 0) z = m / x;
    		int cnt = 1;
    		while(z >= cnt){
    			w[++len] = x * cnt;
    			c[len] = y * cnt;
    			z -= cnt;
    			cnt <<= 1;
    		}
    		if(z){
    			w[++len] = x * z;
    			c[len] = y * z;
    		}
    	}
    	for(int i = 1 ; i <= len ; i++){
    		for(int j = m ; j >= w[i] ; j--){
    			dp[j] = max(dp[j], dp[j - w[i]] + c[i]);
    		}
    	}
    	cout << dp[m];
    	return 0;
    } 
    
    

    信息

    ID
    3275
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    191
    已通过
    75
    上传者