백준
백준 소스코드 [C++] 12865 평범한 배낭
Hani_Levenshtein
2020. 12. 10. 20:33
12865번: 평범한 배낭
첫 줄에 물품의 수 N(1 ≤ N ≤ 100)과 준서가 버틸 수 있는 무게 K(1 ≤ K ≤ 100,000)가 주어진다. 두 번째 줄부터 N개의 줄에 거쳐 각 물건의 무게 W(1 ≤ W ≤ 100,000)와 해당 물건의 가치 V(0 ≤ V ≤ 1,000)
www.acmicpc.net
백준 소스코드 [C++] 12865 평범한 배낭
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int bag[100001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, value, weight;
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> weight >> value;
for (int j = m;weight<=j;j--)
bag[j] = max(bag[j], bag[j - weight] + value);
}
cout << bag[m];
return 0;
}