Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - 1563
- 티스토리챌린지
- NRVO
- UE5
- 오블완
- UnrealEngine4
- 2294
- GeeksForGeeks
- Frustum
- softeer
- 백준
- 언리얼엔진5
- C
- UnrealEngine5
- Unreal Engine5
- const
- RootMotion
- Programmers
- directx
- 팰린드롬 만들기
- RVO
- C++
- 프로그래머스
- winapi
- 줄 세우기
- DirectX11
- algorithm
- TObjectPtr
- baekjoon
- IFileDialog
                            Archives
                            
                        
                          
                          - Today
- Total
Game Develop
[Algorithm]Baekjoon 15661번 :: 링크와 스타트 본문
https://www.acmicpc.net/problem/15661
| 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 | #include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <math.h> #include <queue> #include <functional> #include <sstream> #include <memory.h> #include <deque> #include <set> #include <unordered_set> using namespace std; int n; int ability[21][21] = { 0 }; vector<int> teams[2]; int answer = 0x3f3f3f3; int GetSumAbility(int team) {     int sum = 0;     for (int i = 0; i < teams[team].size() -1 ; ++i)     {         for (int j = i + 1; j < teams[team].size(); ++j)         {             int a = teams[team][i];             int b = teams[team][j];             sum += ability[a][b] + ability[b][a];         }     }     return sum; } void DFS(int index) {     if (teams[0].size() + teams[1].size() == n)     {         if (teams[0].size() > 0 && teams[1].size() > 0)         {             answer = min(answer, abs(GetSumAbility(0) - GetSumAbility(1)));         }         return;     }     for (int i = 0; i < 2; ++i)     {         teams[i].push_back(index + 1);         DFS(index + 1);         teams[i].pop_back();     } } int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i)     {         for (int j = 0; j < n; ++j)         {             cin >> ability[i][j];         }     }     DFS(-1);     cout << answer; } | cs | 
n명의 팀원이 주어지고 두 팀으로 나눴을 때 능력치의 총합차이가 최소가 되게해야하는 문제이다.
이 문제에서 포인트는 그냥 팀을 잘 나눠주기만 하면 된다. n과 m시리즈를 풀어봤으면 쉽게 풀어봤을, 모든 경우를 뽑아보는 문제이다.
그냥 매 차례마다 특정팀에 넣고 탐색진행 후, 다시 뺸다음 두번째팀에 넣고 탐색진행 후 다시 뺴기... 이런식으로 했다.
왜냐면 특정 플레이어는 동시에 두 팀에 소속되어있을 수 없으니, 다른팀에 넣기위해선 빼줘야 한다.
탐색을 진행하다 두 팀에 소속된 플레이어수가 n명만큼 되면 비교를 해줬다.
'Algorithm > Baekjoon' 카테고리의 다른 글
| [Algorithm]Baekjoon 29756번 :: DDR 체력 관리 (0) | 2025.03.17 | 
|---|---|
| [Algorithm]Baekjoon 3649번 :: 로봇 프로젝트 (0) | 2025.03.17 | 
| [Algorithm]Baekjoon 2617번 :: 구슬 찾기 (0) | 2025.03.17 | 
| [Algorithm]Baekjoon 2211번 :: 네트워크 복구 (0) | 2025.03.17 | 
| [Algorithm]Baekjoon 1774번 :: 우주신과의 교감 (0) | 2025.03.17 | 
