| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 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 |
- ์ฝ๋ฉ ํ ์คํธ
- benefits
- ํด์ค
- ์ํ
- ์นด์นด์ค
- lululemon
- ์์ด
- ๊ฑด๊ฐ
- Algorithm
- ์๊ณ ๋ฆฌ์ฆ
- ๐
- health
- ํ๋ฉ์ด๋
- silver
- 2020
- BOJ
- ์๋จ
- ์์ ํ์
- ์ถ์ฒ
- BFS
- ๋์
- Netflix
- ๋ฐฑ์ค
- coding
- ๋์์๋จ
- ํ์ฟก
- usaco
- ๋ฆฌ๋ทฐ
- ๋ทํ๋ฆญ์ค
- ์๋ฅ
- Today
- Total
Lemonlover๐ง๐ปโ๏ธ
BOJ - ์ฃผ์ฌ์ ์ท๋์ด (17825) [2019 ์ผ์ฑ SW ๊ธฐ์ถ] ๋ณธ๋ฌธ
BOJ - ์ฃผ์ฌ์ ์ท๋์ด (17825) [2019 ์ผ์ฑ SW ๊ธฐ์ถ]
Summer_lulu 2019. 12. 7. 01:08https://www.acmicpc.net/problem/17825
17825๋ฒ: ์ฃผ์ฌ์ ์ท๋์ด
์ฒซ์งธ ์ค์ ์ฃผ์ฌ์์์ ๋์ฌ ์ 10๊ฐ๊ฐ ์์๋๋ก ์ฃผ์ด์ง๋ค.
www.acmicpc.net
2019๋ ํ๋ฐ๊ธฐ ์ผ์ฑ ๊ธฐ์ถ๋ฌธ์ ์ ๋๋ค.
์ด ๋ฌธ์ ์์ ๊ฐ์ฅ ์ด๋ ค์ด ์ ์ ๋ฐ๋ก '๋์์ธ'์ ๋๋ค.
๋๋์ฒด ์ด ์ท๋์ด ํ์ ์ด๋ป๊ฒ ๋์์ธํด์ผ ํ๋๊ฐ...?
์ฒ์ ํด๋ณธ๋ค๋ฉด ๊ต์ฅํ ๋ํดํฉ๋๋ค.
1. ์ ์ฌ๊ฐ ๋ฐฐ์ด์ ๋ง๋ค์ด ๋๊ฐ์ด ๊ทธ๋ฆฐ๋ค.
2. ์์ ํ๋์ ๋ ธ๋๋ผ๊ณ ์๊ฐํ๊ณ , ๊ทธ๋ํ๋ก ์๊ฐํ์ฌ ๋์์ธํ๋ค.
์๋ฌด๋๋ directed graph๋ก ์๊ฐํ๊ณ ๋์์ธํ๋๊ฒ ํจ์ฌ ์ฌ์ ๋ณด์ ๋๋ค.
๋ค๋ง, ํ๋์ ๋ ธ๋์์ ์์ํ ๋, ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก ๊ฐ๊ฒ๋ ํด์ฃผ๋ ์ฝ๋๋ฅผ ์์ฑํด์ฃผ๋ฉด ๋ฉ๋๋ค.
๋ ธ๋ ๊ฐฏ์๊ฐ ์ด 33๊ฐ ์ ๋(?) ๋๋ ๊ฒ ๊ฐ๋ค์.
๋ญ ์ด์ ๋๋ฉด ... ์ฌ์ค ๋งค์ฐ ๋ง์ ํธ์ด๊ธดํ๋ฐ ๋ถ๊ฐ๋ฅํ ์ ๋๋ ์๋๊ธฐ์
ํ๋ํ๋ ์ฝ๋๋ก ์์ฑํด ์ค๋๋ค.
๋์์ธ์ด ๋๋ฌ๋ค๋ฉด, ๊ทธ ๋ค์์ ๋ค๋ฅธ ๋ฌธ์ ๋ค๊ณผ ๋ค๋ฅธ ์ ์ด ์์ต๋๋ค.
๋ฐ๋ก '์์ ํ์'์ ๋๋ค.
์๊ฐ ๋ณต์ก๋๋ ๋์ถฉ ์ก์ผ๋ฉด 4^10 ์ ๋๋ค. ์ฝ 1000000 ์ ๋๋ค. ์๊ฐ ์์ ์ถฉ๋ถํ ๊ฐ๋ฅํ์ฃ !
์ ๊ฐ ์์๋ก ๋์์ธํ ๋ด์ฉ๋ค์ ์๋ ๊ทธ๋ฆผ์ผ๋ก ๊ทธ๋ ค๋ดค์ต๋๋ค.
๋ ธ๋ ๋ฒํธ๋ฅผ ์์๋ก ๋ฐฐ์ ํด์ฃผ๊ณ , adjacent list ๋ฅผ ํตํด ๊ทธ๋ํ์ ์ฃ์ง๋ค์ ํํํด์ฃผ์์ต๋๋ค.
๋ฉ์ธ ํจ์ ์ฒ์์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค์ฃผ๋ ๋ถ๋ถ์ ์ ์ฌํ ๋ณด๊ณ , ์๋ ๊ทธ๋ฆผ๊ณผ ๋น๊ตํด๋ณด์๋ฉด ๋ค์์ ์ด๋ฐ ๋ฌธ์ ๋ฅผ ํ ๋
์ด๋ป๊ฒ ํด์ผ ํ๋์ง ๊ฐ์ ์ก์ผ์ค ์ ์์ต๋๋ค!

|
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include <iostream>
#include <vector>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;
int v[33][2];
int score[33];
vector<int> yut; // ์ท๋์ด 10๊ฐ ๊ฒฐ๊ณผ ๋ฐ๋ ๋ณ์
int ans;
int pos[5]; // 4๊ฐ์ ๋ง์ ํ์ฌ์์น
bool chk[33]; // ํ์ฌ ๋
ธ๋์ ๋ง์ด ์กด์ฌํ๋์ง๋ฅผ ํ์ธํ๊ธฐ ์ํ ๋ฐฐ์ด
bool change_dir[33]; // ์์ ๋
ธ๋๊ฐ ๋ฐฉํฅ์ ๋ฐ๊ฟ์ผ ํ๋์ง ํ์ธํ๊ธฐ ์ํ ๋ฐฐ์ด
void sol(int cur, int total){
if(cur == 10){
ans = max(ans, total);
return;
}
int tries = yut[cur];
for(int i = 0; i < 4; i++){
int tmp = tries;
int position = pos[i];
int temp_pos = position;
if(change_dir[position]){
tmp -= 1;
position = v[position][1];
}
while(tmp--) position = v[position][0];
if(position != 21 && chk[position]) continue; // 21๋ฒ ๋
ธ๋๊ฐ ๋ง์ง๋ง ๋
ธ๋๋ก ์ธํ
๋์ด ์์ผ๋ฏ๋ก ๋ฌด์ํด์ค๋ค
// ์ด๊ณณ์ผ๋ก ์๋ค๋ ๊ฒ์ ๊ฐ ์ ์๋ค๋ ๊ฒ์ด๋ค
// ๋ฐ๋ผ์ chk, pos ๋ฐฐ์ด์ ๊ฐ์ ๋ณํ์์ผ, ๋ง์ ์์น๊ฐ ๋ณํ๋ค๋ ํํ์ ํด์ค๋ค
pos[i] = position;
chk[temp_pos] = false;
chk[position] = true;
// ๋ง์ ์์น๋ฅผ ์ด๋์ํจ ํ ๊ทธ ๋ค์์ผ๋ก ๋์ด๊ฐ๋ค
sol(cur + 1, total + score[position]);
// ๋ค์ ๋ง์ ์์น๋ฅผ ์๋ ์์๋ ๊ณณ์ผ๋ก ๋๋๋ ค
chk[position] = false;
chk[temp_pos] = true;
pos[i] = temp_pos;
}
}
int main(){
// ๊ฐ ๋
ธ๋์ ๊ทธ ๋ค์๋
ธ๋ ์ธํ
, ์ฆ ์ด๊ฒ์ด ํ์ดํ ์ธํ
์ด๋ผ๊ณ ๋ณด๋ฉด ๋๋ค.
for(int i = 0; i <= 24; i++){
v[i][0] = i + 1;
}
v[21][0] = 21;
v[25][0] = 31;
v[26][0] = 25;
v[27][0] = 26;
v[28][0] = 27;
v[29][0] = 30;
v[30][0] = 25;
v[31][0] = 32;
v[32][0] = 20;
v[5][1] = 22;
v[10][1] = 29;
v[15][1] = 28;
change_dir[5] = change_dir[10] = change_dir[15] = true; // ์ด ๊ณณ์์ ์์ํ๋ฉด, ๋ฐฉํฅ์ ๋ฐ๊ฟ์ค์ผํ๊ธฐ ๋๋ฌธ์ ์ค์ ํด์ค๋ค.
// ์ ์์ธํ
for(int i = 1; i <= 20; i++) score[i] = 2 * i;
for(int i = 22; i <= 24; i++) score[i] = 13 + 3 * (i - 22);
score[25] = 25;
for(int i = 26; i <= 28; i++) score[i] = i;
score[31] = 30;
score[32] = 35;
score[29] = 22;
score[30] = 24;
yut.resize(10);
for(int i = 0; i < 10; i++)
cin >> yut[i];
sol(0, 0);
cout << ans << endl;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'์ฝ๋ฉ ํ ์คํธ ๋๋น ์ถ์ฒ ๋ฌธ์ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| BOJ - ์ผ์ผํ ์ (17252) (0) | 2019.12.10 |
|---|---|
| BOJ - N์ผ๋ก ๋ง๋ค๊ธฐ (17255) (0) | 2019.12.09 |
| BOJ - ๊ณต์ฃผ๋์ ๊ตฌํด๋ผ! (17836) (0) | 2019.12.03 |
| BOJ - ์นด๋ ๋๊ธฐ (5568) (0) | 2019.12.03 |
| BOJ - ๋ง๋ผํค1 (10655) (0) | 2019.12.03 |