Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 5639
- Unreal
- 2단계로킹
- 셰그먼트트리
- Security
- UActor
- 1759번
- Linux
- SQL
- 실습
- UnrealMP
- 비재귀셰그먼트
- 트랜잭션 관리
- OS
- 오손데이터읽기
- 의미와 무의미의 경계에서
- objtofbx
- 1967번
- C++
- 백준
- hackerank
- 민겸수
- 언리얼 플러그인
- FBX
- 언리얼 커스텀 플러그인
- oracle
- 백준 1253번
- command not found
- 1253번
- 데이터베이스 배움터
Archives
- Today
- Total
fatalite
동전 2 - 2294번 백준 본문
문제
문제 난이도 : 골드 5
문제 분류 : 다이나믹 프로그래밍
문제 리뷰
DP는 어렵다.,..
문제 소스 코드
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <memory.h>
using namespace std;
void Init()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout.tie(NULL);
}
int Coin[101];
int DP[100001];
int main()
{
Init();
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> Coin[i];
}
for (int i = 0; i < 100001; i++) {
DP[i] = 999999;
}
DP[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = Coin[i]; j <= k; j++) {
DP[j] = min(DP[j - Coin[i]] + 1, DP[j]);
}
}
if (DP[k] == 999999) {
cout << -1;
}
else {
cout << DP[k] << endl;
}
}
'코딩 인터뷰 > Dynamic Programming' 카테고리의 다른 글
가장 큰 증가하는 부분 수열 - 11055번 백준 (0) | 2023.10.20 |
---|---|
오르막 수 - 11057번 백준 (0) | 2023.10.14 |
카드 구매하기 - 11052번 백준 (0) | 2023.10.13 |
파도반 수열 - 9461번 백준 (1) | 2023.10.13 |
파이프 옮기기 1 - 17070번 백준 (2) | 2023.09.24 |