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
- Camera Zoom
- rpg server
- Digital Ocean
- server
- Packet Network
- draganddrop
- Google Refund
- MySQL
- Unity IAP
- screencapture
- springboot
- linux
- docker
- OverTheWire
- Spring Boot
- Camera Movement
- Google Developer API
- express
- java
- nodejs
- --watch
- spread 연산자
- Git
- Unity Editor
- mongoDB
- critical rendering path
- css framework
- unity
- SDK upgrade
- react
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 3. 거스름돈 본문
https://school.programmers.co.kr/learn/courses/30/lessons/12907
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
실패방법 -> DFS로 찾기 . 시간초과발생함.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int answer =0;
void find(int n, vector<int> money){
if(n<=0 ||money.size() ==0) return;
int price = money[0];
int value= n/price;
money.erase(money.begin());
if(n%price ==0) answer = (answer + 1)%1000000007; //해당재화 다사용하기~
for(;value >=0; value--){
int crr = value*price;
find(n-crr,money);
}
}
int solution(int n, vector<int> money) {
sort(money.rbegin(), money.rend());
find(n, money);
return answer;
}
성공 => DP 로 풀기. 항상 DP는 내머리속에서 나오기가 힘들다 ㅠ
#include <vector>
using namespace std;
int solution(int n, vector<int> money) {
vector<int> dp(n + 1, 0);
dp[0] = 1; // 0원을 만드는 방법은 1가지
for (int coin : money) { // 각 동전에 대해
for (int i = coin; i <= n; i++) { // 금액을 만들면서
dp[i] = (dp[i] + dp[i - coin]) % 1000000007;
}
}
return dp[n]; // 최종적으로 n원을 만드는 방법의 수 반환
}'Algorithm(c++) > Level 3' 카테고리의 다른 글
| [프로그래머스] Level 3. 파괴되지 않은 건물 (0) | 2025.03.14 |
|---|---|
| [프로그래머스] Level 3. 순위 (0) | 2025.03.13 |
| [프로그래머스] Level 3. 셔틀버스 (0) | 2025.03.12 |
| [프로그래머스] Level 3. 가장 긴 팰린드롬 (0) | 2025.03.10 |
| [프로그래머스] Level 3. 디스크 컨트롤러 (0) | 2025.03.09 |