Posts 12865 평범한 배낭
Post
Cancel

12865 평범한 배낭

12865 평범한 배낭

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int numOfObject, weight, DP[101][100001];

int main() {
	cin >> numOfObject >> weight;
	for (int i = 1; i <= numOfObject; i++) {
		int w, v;
		cin >> w >> v;
		for (int j = 1; j <= weight; j++) {
			if (j >= w)
				DP[i][j] = DP[i - 1][j - w] + v > DP[i - 1][j] ? DP[i - 1][j - w] + v : DP[i - 1][j];
			else
				DP[i][j] = DP[i - 1][j];
		}
	}
	cout << DP[numOfObject][weight];
}
This post is licensed under CC BY 4.0 by the author.

9527 1의 개수세기

13460 Gold 2

Comments powered by Disqus.