https://www.acmicpc.net/problem/3980
3980번: 선발 명단
각각의 테스트 케이스에 대해서, 모든 포지션의 선수를 채웠을 때, 능력치의 합의 최댓값을 한 줄에 하나씩 출력한다. 항상 하나 이상의 올바른 라인업을 만들 수 있다.
www.acmicpc.net
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
|
#include <iostream>
#include <vector>
#include <algorithm>
int abi[12][12];
bool chk[11];
using namespace std;
void go(int index, int sum, vector<int> &hap)
{
if (index == 11)
{
hap.push_back(sum);
return;
}
for (int j = 0; j < 11; j++)
{
if (abi[index][j] > 0)
{
if (chk[j] == true)
continue;
chk[j] = true;
sum += abi[index][j];
go(index + 1, sum, hap);
sum -= abi[index][j];
chk[j] = false;
}
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 11; j++)
cin >> abi[i][j];
}
vector<int> hap;
go(0, 0, hap);
int ans = 0;
for (int i = 0; i < hap.size(); i++)
{
if (ans < hap[i])
ans = hap[i];
}
cout << ans << '\n';
}
}
|
cs |
고른 포지션은 골라선 안된다! chk
다른 경우를 할 때는 합을 다시 원래대로 돌려놔야한다! sum -=
'브루트 포스 > 브루트포스(재귀)' 카테고리의 다른 글
N-Queen (중요!) (0) | 2023.04.01 |
---|---|
테트로미노 (중요!) (0) | 2023.04.01 |
연산자 끼워넣기 (재귀) (0) | 2023.03.25 |
부분수열의 합 (재귀, 비트마스크) (0) | 2023.03.21 |
로또 (0) | 2023.03.20 |