Submission #598703

#TimeUsernameProblemLanguageResultExecution timeMemory
598703sshoney1Knapsack (NOI18_knapsack)C++17
37 / 100
116 ms1128 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 100000;
const int S = 2000;

int v[N + 1], w[N + 1], k[N + 1], s, n, dp[N + 1][S + 1];

int f(int cur_ind, int cur_w){
	if(cur_ind > n) return 0;
	
	if(dp[cur_ind][cur_w] != -1) return dp[cur_ind][cur_w];
	
	int a = 0;
	
	for(int i = 0; i <= k[cur_ind]; i++){
		if(cur_w + i*w[cur_ind] <= s){
			a = max(a, f(cur_ind + 1, cur_w + i*w[cur_ind]) + v[cur_ind]*i);
		}
	}	
	
	return dp[cur_ind][cur_w] = a;
}

int main(){
	
	cin >> s >> n;
	
	for(int i = 1; i <= n; i++){	
		cin >> v[i] >> w[i] >> k[i]; 
		for(int j = 0; j <= s; j++){
			dp[i][j] = -1;
		}
	}
	
	cout << f(1, 0);
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...