반응형

https://www.acmicpc.net/problem/14728

 

14728번: 벼락치기

ChAOS(Chung-ang Algorithm Organization and Study) 회장이 되어 일이 많아진 준석이는 시험기간에도 일 때문에 공부를 하지 못하다가 시험 전 날이 되어버리고 말았다. 다행히도 친절하신 교수님께서 아래와

www.acmicpc.net

 

 

[ 문제풀이 ]

 

이 문제를 풀기 전에 다음 글을 먼저 읽고 오시는 것을 추천드립니다.

https://rudalsd.tistory.com/20

 

[ 백준 ] 12865번 - 평범한 배낭 (C++)

https://www.acmicpc.net/problem/12865 12865번: 평범한 배낭 첫 줄에 물품의 수 N(1 ≤ N ≤ 100)과 준서가 버틸 수 있는 무게 K(1 ≤ K ≤ 100,000)가 주어진다. 두 번째 줄부터 N개의 줄에 거쳐 각 물건의 무게 W(1

rudalsd.tistory.com

 

[ 소스코드 ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
 
using namespace std;
 
int N, T;
pair<intint> arr[101];
int ans[101][10001];
 
int main()
{
    scanf("%d %d"&N, &T);
 
    for (int i = 1; i <= N; i++) {
        scanf("%d %d"&arr[i].first, &arr[i].second);
    }
 
    for (int i = 1; i <= N; i++) {
        int cost = arr[i].first;
        int point = arr[i].second;
 
        for (int j = 1; j <= T; j++) {
            if (j < cost) {
                ans[i][j] = ans[i - 1][j];
            }
            else {
                ans[i][j] = max(ans[i - 1][j], ans[i - 1][j - cost] + point);
            }
        }
    }
 
    printf("%d", ans[N][T]);
}
cs
반응형

'백준' 카테고리의 다른 글

[ 백준 ] 17845번 - 수강 과목 (C++)  (0) 2023.04.05
[ 백준 ] 1321번 - 군인 (C++)  (0) 2023.04.04
[ 백준 ] 13424번 - 비밀 모임 (C++)  (0) 2023.04.02
[ 백준 ] 1719번 - 택배 (C++)  (0) 2023.04.01
[ 백준 ] 13023번 - ABCDE (C++)  (0) 2023.03.31

+ Recent posts