Skip to content

Commit e98ef33

Browse files
committed
Quartz sync: Nov 25, 2025, 6:36 PM
1 parent 83a4305 commit e98ef33

File tree

7 files changed

+660
-142
lines changed

7 files changed

+660
-142
lines changed

content/About.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
aliases:
33
description:
44
created: 2025-05-18
5-
modified: 2025-08-14
5+
modified: 2025-11-25
66
title: About
77
comments: "true"
88
---
@@ -23,5 +23,7 @@ comments: "true"
2323
- [Sweep Keyboard](https://github.com/codeyoma/sweep-nice-nano)
2424
- [Yòmá's Library](https://lib.yoma.kr/)
2525

26+
<!--
2627
### Badge
2728
[![Yoma's Solved.ac profile](http://mazassumnida.wtf/api/v2/generate_badge?boj=hiatus4322)](https://solved.ac/profile/hiatus4322)
29+
-->

content/Computer Science/1 Foundations & Theory/Algorithms/ps/boj/1162/1162.md

Lines changed: 0 additions & 141 deletions
This file was deleted.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
tags: ["ps/boj/gold/4", "ps/boj/gold", "cs/algorithms/bruteforcing/ps","cs/algorithms/backtracking/ps"]
3+
---
4+
5+
# Problem
6+
- [https://www.acmicpc.net/problem/19942](https://www.acmicpc.net/problem/19942)
7+
- [code on boj](https://www.acmicpc.net/status?problem_id=19942&user_id=hiatus4322)
8+
- [code on github](https://github.com/codeyoma/ps/tree/main/boj/19942)
9+
10+
11+
<br/>
12+
13+
<!--
14+
# Logic
15+
16+
### *분석*
17+
- 문제 유형 (알고리즘...)
18+
- 제약 조건 (인풋 크기, 예외 값, 시공간 복잡도...)
19+
20+
### *설계*
21+
1. 알고리즘 선택
22+
2. 자료구조 선택
23+
3. 수도 코드 작성
24+
4. 정합판단
25+
- `1 ~ 3`과정으로 도출된 로직이 문제를 해결하는가
26+
- 그렇다 -> **구현**
27+
- 잘 모르겠다 -> **구현**
28+
- 아니다 -> 1번부터 다시 점검
29+
30+
### *구현*
31+
- 로직 검증
32+
33+
### *테스트*
34+
- 예외 케이스 고려
35+
36+
<br/>
37+
38+
-->
39+
40+
# My Code
41+
42+
## cpp
43+
```cpp title="boj/19942.cpp"
44+
// https://www.acmicpc.net/problem/19942
45+
#include <iostream>
46+
using namespace std;
47+
48+
#ifdef LOCAL
49+
# define LOG clog
50+
#else
51+
struct nullstream : ostream {
52+
nullstream()
53+
: ostream(nullptr) {}
54+
};
55+
nullstream LOG;
56+
#endif
57+
58+
void fast_io() {
59+
ios_base::sync_with_stdio(false);
60+
cin.tie(nullptr);
61+
}
62+
63+
//--------------------------------------------------------------------------------------------------
64+
65+
#define MAX (1234567891)
66+
#define MIN (-1234567891)
67+
#include <vector>
68+
69+
using namespace std;
70+
71+
int N;
72+
int Con[4];
73+
int Ing[15][5];
74+
int minPrice = 15 * 500;
75+
vector<int> bestChoice;
76+
77+
void backtracking(int sum[5], vector<int> choice, int idx) {
78+
for (int i = 0; i < 4; i++) {
79+
if (sum[i] < Con[i]) {
80+
return;
81+
}
82+
}
83+
if (minPrice > sum[4] || (minPrice == sum[4] && choice < bestChoice)) {
84+
minPrice = sum[4];
85+
bestChoice = choice;
86+
}
87+
for (int i = idx; i < N; i++) {
88+
int newsum[5];
89+
vector<int> newchoice = choice;
90+
memcpy(newsum, sum, sizeof(int) * 5);
91+
newchoice.push_back(i + 1);
92+
for (int j = 0; j < 5; j++) {
93+
newsum[j] -= Ing[i][j];
94+
}
95+
backtracking(newsum, newchoice, i + 1);
96+
}
97+
}
98+
99+
int main() {
100+
fast_io();
101+
int sum[5] = {
102+
0,
103+
};
104+
105+
cin >> N;
106+
107+
for (int i = 0; i < 4; i++) {
108+
cin >> Con[i];
109+
}
110+
111+
for (int i = 0; i < N; i++) {
112+
for (int j = 0; j < 5; j++) {
113+
int input;
114+
cin >> input;
115+
Ing[i][j] = input;
116+
sum[j] += input;
117+
}
118+
}
119+
vector<int> choice;
120+
121+
backtracking(sum, choice, 0);
122+
cout << minPrice << "\n";
123+
int idx = 0;
124+
for (int i = 1; i <= N; i++) {
125+
if (idx < bestChoice.size() && i == bestChoice[idx]) {
126+
idx++;
127+
} else {
128+
cout << i << " ";
129+
}
130+
}
131+
}
132+
```

0 commit comments

Comments
 (0)