๋ฌธ์ ๋งํฌ
17825๋ฒ: ์ฃผ์ฌ์ ์ท๋์ด (acmicpc.net)
17825๋ฒ: ์ฃผ์ฌ์ ์ท๋์ด
์ฃผ์ฌ์ ์ท๋์ด๋ ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ํ์์ ํ๋ ๊ฒ์์ด๋ค. ์ฒ์์๋ ์์ ์นธ์ ๋ง 4๊ฐ๊ฐ ์๋ค. ๋ง์ ๊ฒ์ํ์ ๊ทธ๋ ค์ง ํ์ดํ์ ๋ฐฉํฅ๋๋ก๋ง ์ด๋ํ ์ ์๋ค. ๋ง์ด ํ๋์ ์นธ์์ ์ด๋์ ์์ํ๋ฉด
www.acmicpc.net
์ฃผ์ฌ์๋ก ์งํ๋๋ ์ท๋์ด๋ฅผ ๊ท์น๋๋ก ๊ตฌํํ๋ ๋ฌธ์ .
ํ์ด
์ผ์ชฝ๊ณผ ๊ฐ์ ์ท๋์ด ํ์ ์ด๋ป๊ฒ ๊ตฌํํ ์ง๊ฐ ์ผ๋จ ์ฒซ๋ฒ์งธ ๋ฌธ์ ์๋ค. ํ๋์ ์นธ์ ๋ฐ์์ ๋ ๊ฒฝ๋ก๊ฐ ๋ฐ๋๋ ๊ฒ์ ์ด๋ป๊ฒ ํํํด์ผํ์ง ์๊ฐํ๋ค๊ฐ, ์ฒ์์ 10, 20, 30 ์นธ์ ๋ฐ์๋๋ง๋ค ๊ฒฝ๋ก๊ฐ ๋ฐ๋๋๊น 4๊ฐ์ง ๊ฒฝ์ฐ์ ๊ฒฝ๋ก๋ฅผ ๋ฐ๋ก ๋ง๋ค๋ ค๊ณ ํ์๋ค. ํ์ง๋ง ๊ทธ๋ ๊ฒํ๋ฉด ์ด๋ํ ์นธ์ ์ด๋ฏธ ๋ง์ด์๋์ง ํ์ ํ๊ธฐ๊ฐ ํ๋ค์๋ค.
๊ทธ๋์ ๋๋ ๋ด ์์๋๋ก ๊ฐ ์นธ๋ง๋ค ๋ฒํธ๋ฅผ ๋ถ์ฌํ๋ค.
์ด๋ ๊ฒ ๊ฐ ์นธ๋ง๋ค ๋ด ๋ง์๋๋ก ๋ฒํธ๋ฅผ ๋ถ์ฌํ๊ณ
๋ค์ ์นธ์ ๋ฒํธ๋ฅผ Next๋ผ๋ ๋ฐฐ์ด์ ๋ง๋ค์ด์ ๋ฏธ๋ฆฌ ์ ํด๋์๋ค.
์๋ฅผ ๋ค์ด 31๋ฒ์นธ ๋ค์์นธ์ 24๋ฒ์นธ์ธ๋ฐ ์ด๋ฐ ๊ฒฝ์ฐ๋ ์ด๋์ด ๋ถ๊ท์น์ ์ด๊ธฐ ๋๋ฌธ์ 31๋ฒ ๋ค์์นธ์ 24๋ฒ์ด๋ผ๊ณ ๋ฏธ๋ฆฌ ๊ฒฝ๋ก๋ฅผ ์ ํด์ ๊ตฌํํ๋ค.
๋ง์ฝ ์ด๋ํ๋ คํ ๋ ์์์นธ์ด 5๋ฒ, 10๋ฒ, 30๋ฒ์ด๋ฉด ๋ค์์นธ์ด ๊ฐ 21, 27, 29๋ฒ์นธ์ด ๋๋๋ก ํ๋ค.
์ด๋ ๊ฒ ํ๊ฒ๋๋ฉด ๊ฒฝ๋ก๋ฅผ ํ๋ํ๋ ์ง์ ํด์ฃผ์ด์ผ ํ๋ค๋ ๋จ์ ์ด ์๊ณ , ์ฝ๋๊ฐ ์กฐ๊ธ ์ง์ ๋ถํด์ง๋ค. ํ์ง๋ง ์ด๊ฒ๋ง๊ณ ๋ค๋ฅด๊ฒ ๊ตฌํํ ๋ฐฉ๋ฒ์ด ์๊ฐ์ด ์๋์ ์ด๋ ๊ฒ ํ๋ค.
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
|
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>
#include <climits>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <map>
#define mod 998244353
using namespace std;
typedef long long ll;
typedef priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Priority_queue;
const int INF = INT_MAX;
const int MAX_N = 30 + 5;
int N, M, T;
int Score[MAX_N];
int Next[MAX_N];
int horse[4];
int Turn[11];
int ans = -1;
void Init();
int Move_horse(int horse_num, int moving);
bool is_ok(int next);
void backtracking(int depth, int total_Score);
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Init();
for (int i = 0; i < 10; i++)
cin >> Turn[i];
backtracking(0, 0);
cout << ans << "\n";
return 0;
}
void Init() {
for (int i = 1; i <= 20; i++)
Score[i] = 2 * i;
Score[27] = 22;
Score[28] = 24;
Score[21] = 13;
Score[22] = 16;
Score[23] = 19;
for (int i = 0; i <= 2; i++)
Score[24 + i] = 25 + 5 * i;
for (int i = 0; i <= 2; i++)
Score[29 + i] = 28 - i;
for (int i = 0; i <= 31; i++)
Next[i] = i + 1;
Next[20] = INF;
Next[31] = Next[28] = 24;
Next[26] = 20;
}
int Move_horse(int horse_num, int moving) {
int now = horse[horse_num];
if (now == 5) {
now = 21;
moving--;
}
else if (now == 10) {
now = 27;
moving--;
}
else if (now == 15) {
now = 29;
moving--;
}
while (moving--) {
now = Next[now];
if (now == INF) {
now = -1;
break;
}
}
return now;
}
bool is_ok(int next) {
for (int i = 0; i < 4; i++)
if (horse[i] != -1 && horse[i] == next)
return false;
return true;
}
void backtracking(int depth, int total_Score) {
if (depth == 10) {
ans = max(ans, total_Score);
return;
}
for (int i = 0; i < 4; i++) {
if (horse[i] == -1)
continue;
int next = Move_horse(i, Turn[depth]);
if (is_ok(next)) {
int temp = horse[i];
horse[i] = next;
if (next == -1)
backtracking(depth + 1, total_Score);
else backtracking(depth + 1, total_Score + Score[next]);
horse[i] = temp;
}
}
}
|
cs |
์ด๋์ด ๋๋ ๋ง์ ์์น๋ฅผ -1๋ก ์ง์ ํด์ ๋์ฐฉํ์์ ํํํ๋ค.
๋ง์ ์์น๊ฐ -1์ธ ๋ง์ ๋์ด์ ์ด๋์ ํ์ง ์๋๋ค.
'๋ฐฑ์ค > Gold' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ] 20055 : ์ปจ๋ฒ ์ด์ด ๋ฒจํธ ์์ ๋ก๋ด (0) | 2022.05.23 |
---|---|
[BOJ] 19238 : ์คํํธ ํ์ (0) | 2022.05.23 |
[BOJ] 17822 : ์ํ ๋๋ฆฌ๊ธฐ (0) | 2022.05.18 |
[BOJ] 17779 : ๊ฒ๋ฆฌ๋งจ๋๋ง 2 (0) | 2022.05.18 |
[BOJ] 17142 : ์ฐ๊ตฌ์ 3 (0) | 2022.05.17 |