Skip to content

Commit 09f21e2

Browse files
committed
Quartz sync: Sep 1, 2025, 10:41 PM
1 parent 4b6454d commit 09f21e2

3 files changed

Lines changed: 250 additions & 2 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
tags: ["ps/boj/gold/5", "ps/boj/gold", "cs/algorithms/dynamic-programming/ps","cs/algorithms/knapsack/ps"]
3+
---
4+
5+
# Problem
6+
- [https://www.acmicpc.net/problem/12865](https://www.acmicpc.net/problem/12865)
7+
8+
<br/>
9+
10+
# Logic
11+
12+
### *분석*
13+
- 문제 유형 (알고리즘...)
14+
- 제약 조건 (인풋 크기, 예외 값, 시공간 복잡도...)
15+
16+
### *설계*
17+
1. 알고리즘 선택
18+
2. 자료구조 선택
19+
3. 수도 코드 작성
20+
4. 정합판단
21+
- `1 ~ 3`과정으로 도출된 로직이 문제를 해결하는가
22+
- 그렇다 -> **구현**
23+
- 잘 모르겠다 -> **구현**
24+
- 아니다 -> 1번부터 다시 점검
25+
26+
### *구현*
27+
- 로직 검증
28+
29+
### *테스트*
30+
- 예외 케이스 고려
31+
32+
<br/>
33+
34+
# My Code
35+
## cpp
36+
```cpp title="boj/12865.cpp"
37+
// https://www.acmicpc.net/problem/12865
38+
// https://codeyoma.github.io/Computer-Science/1-Foundations--and--Theory/Algorithms/ps/boj/12865/12865
39+
#include <iostream>
40+
using namespace std;
41+
42+
#ifdef LOCAL
43+
# define LOG clog
44+
#else
45+
struct nullstream : ostream {
46+
nullstream()
47+
: ostream(nullptr) {}
48+
};
49+
nullstream LOG;
50+
#endif
51+
52+
void fast_io() {
53+
ios_base::sync_with_stdio(false);
54+
cin.tie(nullptr);
55+
}
56+
57+
//--------------------------------------------------------------------------------------------------
58+
59+
#define MAX (1234567891)
60+
#define MIN (-1234567891)
61+
62+
#include <iostream>
63+
#include <vector>
64+
65+
struct item {
66+
int value;
67+
int weight;
68+
};
69+
70+
int main() {
71+
fast_io();
72+
73+
// logic
74+
int n, k;
75+
cin >> n >> k;
76+
77+
vector<item> items(n + 1);
78+
79+
// 0행, 0열 필요
80+
// 이전 배낭의 무게에 현재 무게를 계산하기위해
81+
for (int i = 1; i <= n; ++i) {
82+
int w, v;
83+
cin >> w >> v;
84+
85+
items[i] = { v, w };
86+
}
87+
88+
vector<vector<int>> dp(n + 1, vector<int>(k + 1));
89+
90+
// i = current item
91+
// w = current targe weight
92+
for (int i = 1; i <= n; ++i) {
93+
for (int w = 1; w <= k; ++w) {
94+
if (items[i].weight > w) {
95+
// 현재 아이템의 무게 공간이 안나온다면, 이전 아이템의 무게일떄의 값 계승
96+
dp[i][w] = dp[i - 1][w];
97+
} else {
98+
dp[i][w] = max(
99+
// 이전 아이템의 무게
100+
dp[i - 1][w],
101+
// 이전 무게에서 현재 아이템의 가능한 무게 공간을 만들고, 그 때의 가치에서, 현재 아이템 가치 더하기
102+
dp[i - 1][w - items[i].weight] + items[i].value);
103+
}
104+
}
105+
}
106+
107+
cout << dp[n][k];
108+
}
109+
110+
```
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
tags: ["ps/boj/gold/3", "ps/boj/gold", "cs/algorithms/dynamic-programming/ps","cs/algorithms/game-theory/ps"]
3+
---
4+
5+
# Problem
6+
- [https://www.acmicpc.net/problem/28218](https://www.acmicpc.net/problem/28218)
7+
8+
<br/>
9+
10+
# Logic
11+
12+
### *분석*
13+
- 문제 유형 (알고리즘...)
14+
- 제약 조건 (인풋 크기, 예외 값, 시공간 복잡도...)
15+
16+
### *설계*
17+
1. 알고리즘 선택
18+
2. 자료구조 선택
19+
3. 수도 코드 작성
20+
4. 정합판단
21+
- `1 ~ 3`과정으로 도출된 로직이 문제를 해결하는가
22+
- 그렇다 -> **구현**
23+
- 잘 모르겠다 -> **구현**
24+
- 아니다 -> 1번부터 다시 점검
25+
26+
### *구현*
27+
- 로직 검증
28+
29+
### *테스트*
30+
- 예외 케이스 고려
31+
32+
<br/>
33+
34+
# My Code
35+
## cpp
36+
```cpp title="boj/28218.cpp"
37+
// https://www.acmicpc.net/problem/28218
38+
// https://codeyoma.github.io/Computer-Science/1-Foundations--and--Theory/Algorithms/ps/boj/28218/28218
39+
#include <iostream>
40+
using namespace std;
41+
42+
#ifdef LOCAL
43+
# define LOG clog
44+
#else
45+
struct nullstream : ostream {
46+
nullstream()
47+
: ostream(nullptr) {}
48+
};
49+
nullstream LOG;
50+
#endif
51+
52+
void fast_io() {
53+
ios_base::sync_with_stdio(false);
54+
cin.tie(nullptr);
55+
}
56+
57+
//--------------------------------------------------------------------------------------------------
58+
59+
#define MAX (1234567891)
60+
#define MIN (-1234567891)
61+
62+
#include <iostream>
63+
#include <vector>
64+
65+
int main() {
66+
fast_io();
67+
68+
// logic
69+
70+
int n, m, k;
71+
cin >> n >> m >> k;
72+
73+
vector<string> map(n);
74+
vector<vector<bool>> dp(n, vector<bool>(m, false));
75+
76+
for (int i = 0; i < n; ++i) {
77+
cin >> map[i];
78+
}
79+
80+
// grundy number
81+
// winning, losing state
82+
// 이전 게임에서 주변에 한게임이라도 졌다면 지금은 이기는게 가능
83+
{
84+
for (int r = n - 1; r >= 0; --r) {
85+
for (int c = m - 1; c >= 0; --c) {
86+
if (map[r][c] == '#') {
87+
continue;
88+
}
89+
bool is_win = false;
90+
91+
if (r + 1 < n && map[r + 1][c] == '.' && dp[r + 1][c] == false) {
92+
is_win = true;
93+
}
94+
95+
if (c + 1 < m && map[r][c + 1] == '.' && dp[r][c + 1] == false) {
96+
is_win = true;
97+
}
98+
99+
for (int d = 1; d <= k; ++d) {
100+
if (r + d < n && c + d < m) {
101+
if (map[r + d][c + d] == '.' && dp[r + d][c + d] == false) {
102+
is_win = true;
103+
}
104+
} else {
105+
break;
106+
}
107+
}
108+
109+
dp[r][c] = is_win;
110+
}
111+
}
112+
}
113+
114+
for (const auto& r: dp) {
115+
for (const auto& c: r) {
116+
LOG << c << " ";
117+
}
118+
LOG << "\n";
119+
}
120+
121+
{
122+
int q;
123+
cin >> q;
124+
125+
while (q--) {
126+
int x, y;
127+
cin >> x >> y;
128+
129+
if (dp[x - 1][y - 1]) {
130+
cout << "First\n";
131+
} else {
132+
cout << "Second\n";
133+
}
134+
}
135+
}
136+
}
137+
138+
```

‎content/index.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ aliases:
33
description: This blog is an excerpt from my Obsidian notes
44
title: Hello Again!
55
created: 2025-05-18
6-
modified: 2025-06-23
6+
modified: 2025-09-01
77
comments: "true"
88
---
99

@@ -19,7 +19,7 @@ Not much to see here — but you’re welcome to look around! : notes on compute
1919
###### MOC
2020
- [[About|About]]
2121
- [[- Computer Science|🗺️ - Computer Science]]
22-
- [[- Algorithms|- Algorithms]]
22+
- [[- Algorithms|🗺️ - Algorithms]]
2323
- [[- PS|🗺️ - PS]]
2424
- [[- Frontend|🗺️ - Frontend]]
2525
- [[- JavaScript|🗺️ - JavaScript]]

0 commit comments

Comments
 (0)