답안 #484680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484680 2021-11-05T03:46:43 Z Ncode Knapsack (NOI18_knapsack) C++14
0 / 100
261 ms 259716 KB
#include <bits/stdc++.h>
using namespace std;

int dp[20005][20005];

const int inf = 1e9+5; 

int main(){
	int S, n;
	cin>>S>>n;
	int v, w, k;
	vector<pair<int, int>> a;
	for(int i=0;i<n;i++){
		cin>>v>>w>>k;
		while(k--) a.push_back({v, w});
	}
	// for(int i=0;i<n;i++){
	// 	for(int j=0;j<=S;j++){
	// 		dp[i][j] = inf;
	// 	}
	// }
	dp[0][0] = 0;
	for(int i=0;i<a.size();i++){
		for(int sum = S; sum >= 0; sum --){
			dp[i][sum] = dp[i-1][sum];
			if(sum >= a[i].second && dp[i-1][sum - a[i].second] + a[i].first > dp[i][sum]){
				dp[i][sum] = dp[i-1][sum - a[i].second] + a[i].first;
			}
		}
	}
	// for(int i=0;i<n;i++){
	// 	for(int j = 0; j<=S; j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}cout<<endl;
	// }
	cout<<dp[a.size() - 1][S]<<'\n';
}

Compilation message

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 259716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 259716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 259716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -