본문 바로가기
알고리즘/DP

11052 카드 구매하기

by tryotto 2020. 2. 27.
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
#include <stdio.h>
#include <vector>
 
using namespace std;
 
int main() {
    int n;
    scanf("%d"&n);
 
    vector<int> arr(n + 10);
    vector<int> dp(n + 10);
    for (int i = 1; i <= n; i++)
        scanf("%d"&arr[i]);
 
    for (int coin = 1; coin <= n; coin++) {
        for (int total = coin; total <= n; total++) {
            int no_coin = dp[total];
            int yes_coin = dp[total - coin] + arr[coin];
 
            if (no_coin < yes_coin)
                dp[total] = yes_coin;
        }
    }
 
    printf("%d", dp[n]);
}
cs


dp 를 1차원 배열로 발상하는게 어려웠던 문제였다.

PS 는 자주 안 하는게 좋은 것 같다.
반수 욕구가 사라진다


'알고리즘 > DP' 카테고리의 다른 글

2302 극장 좌석  (0) 2020.02.28
11066 파일합치기  (0) 2020.02.28
DP정리> 동전 문제  (0) 2020.01.12
DP 정리> 타일 채우기  (0) 2020.01.12
1720 타일코드  (0) 2020.01.11