1. ๋ฌธ์ ์ ๋ํ์ฌ ๐ฆ
- ๋ฌธ์ ๋งํฌ: https://www.acmicpc.net/problem/3980
(1) ์กฐ๊ฑด ๋ถ์ ๐
- 2์ฐจ์ ๋ฐฐ์ด๋ก 11๋ช
์ ์ ์์ ํฌ์ง์
๋ณ ๋ฅ๋ ฅ์น๊ฐ ์ฃผ์ด์ง๋ค.
- ๋ง์ฝ members(i)(j) = k ๋ผ๋ฉด, i๋ฒ ์ ์์ j ํฌ์ง์ ๋ฅ๋ ฅ์น๋ k๋ผ๋ ๋ป์ด๋ค.
- ๋ง์ฝ members(i)(j) = 0 ๋ผ๋ฉด, i๋ฒ ์ ์๋ j ํฌ์ง์ ์์ ๋ธ ์ ์๋ค.
- 11๋ช ์ ์ ์๋ฅผ ํฌ์ง์ ์ ์ ๋ฐฐ์นํด์ ๋ฅ๋ ฅ์น ํฉ๊ณ์ ์ต๋์น๋ฅผ ์ถ๋ ฅํ๋ผ.
2. ์ฝ๋๊ฐ ๋์ค๊ธฐ๊น์ง ๐ ๏ธ
KEY WORD
: ์์ด
, ๋ฐฑํธ๋ํน
- ์์ด๋ก ํฌ์ง์
๋ณ ์ ์ ๋ฝ๊ธฐ
- ์ด๋ ํ์ฌ ์กฐํ ์ค์ธ ์ ์๊ฐ ํด๋น ํฌ์ง์ ์์ ๋ธ ๋ฅ๋ ฅ์ด ์๋ค๋ฉด ๋์ด๊ฐ -> ๋ฐฑํธ๋ํน
- base-case์์ ์ ์๋ค์ ํฌ์ง์ ๋ณ ๋ฅ๋ ฅ์น ํฉ๊ณ๋ฅผ ๋ธ๋ค.
- ์ต๋์น๋ฅผ ๊ฐฑ์ ํ๋ค.
(1) ์๊ฐ๋ณต์ก๋ ๋ถ์ โณ
11! = 41,896,800 ์ด๋ผ์ 1์ต์ ์ ๋์ด์ ๊ด์ฐฎ์ ๊ฑฐ ๊ฐ๋ค.
๋ํ ๋์ค์ ๋ฐฑํธ๋ํน ์์๋ฅผ ๋ฃ์๊ธฐ์ ์ค์ ๊ณ์ฐ ๊ฒฝ์ฐ์ ์๋ ๋ ์ค์ด๋ค ๊ฒ์ด๋ค.
3. ์ฝ๋ ๐
(1) SUDO CODE ๐ฌ
์์ฌ ์ฝ๋๋ ์์ ์ค๋ช
๊ณผ ๊ฐ์์ ์๋ตํ๋ค.
(2) JAVA CODE โ
import java.util.*;
import java.io.*;
public class Main {
static int answer = 0;
static int [][] members;
static boolean [] isVisited;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int TC = Integer.parseInt(br.readLine());
for(int t = 0; t < TC; t++){
members = new int [11][11];
for(int i = 0; i < 11; i++){
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j = 0; j < 11; j++){
members[i][j] = Integer.parseInt(st.nextToken());
}
}
isVisited = new boolean [11];
permutation(0, new int [11]);
System.out.println(answer);
answer=0;
}
}
// members์ ํ = ์ ์ ๋ฒํธ, ์ด์ ํฌ์ง์
// answer์ index = ์ ์ ๋ฒํธ, answer์ value = ํฌ์ง์
// isVisited์ index = ํฌ์ง์
, value = ํฌ์ง์
์ผ๋์ง ์๋์ง
public static void permutation(int depth, int [] position) {
// base-case
if(depth == 11) {
int sum = 0;
for(int i = 0; i < 11; i++){
sum += members[i][position[i]];
}
answer = Math.max(answer, sum);
return;
}
for(int i = 0; i < 11; i++) {
if(isVisited[i]) continue;
if(members[depth][i] == 0) continue;
isVisited[i] = true;
position[depth] = i;
permutation(depth+1, position);
isVisited[i] = false;
}
}
}
4. ํธ๋ฌ๋ธ ์ํ or ๋ฐฐ์ด ์ ๐
(1) ํ๋ฆฐ ๋ถ๋ถ (answer๋ฅผ TC๋ง๋ค ์ด๊ธฐํ ์ํจ)
- tc๊ฐ ์ฃผ์ด์ง๊ณ , ๋ชจ๋ ๋ณ์๋ฅผ tc๋ฒ ์ฌํ์ฉ ํด์ผํ๋๋ฐ ๊ทธ๊ฒ์ ํ์ง ์์์ ํ๋ ธ๋ค.
0