[BOJ] 12865 평범한 배낭

Time Lapse :5min 0sec

12865.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <vector>
using namespace std;

int main(void) {
int N, M;
vector<int> DP(100001,0);
int V[101];
int C[101];
scanf("%d %d",&N,&M);
for(int i=1;i<=N;i++){
scanf("%d %d",&V[i],&C[i]);
}
for(int i = 1; i<= N;i++){
for(int j = M; j >= V[i]; j--){
DP[j] = DP[j-V[i]] + C[i] > DP[j] ? DP[j-V[i]] + C[i] : DP[j];
}
}
printf("%d\n",DP[M]);
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/12865/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.