250x250
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 |
Tags
- englishbook
- 프로그래머스
- sw expert academy
- 코테 준비
- 알고리즘 문제
- swexpertacademy
- 쉬운 알고리즘 문제
- 알고리즘
- 코테
- D4
- 삼성
- 백준
- readingbook
- the midnight library
- 코딩테스트
- sw expert
- 직무면접
- 원서
- 코테 대비
- 원서읽자
- 완전탐색
- English
- MySQL
- STUDYENGLISH
- SQL
- BFS
- dfs
- nightroutine
- PyQt
- 원서읽기
Archives
- Today
- Total
시나브로
14889 스타트와 링크 본문
728x90
조합을 이용하여 팀을 나눈다.
Solution
- 조합을 이용해 팀을 나눈다
- 팀별로 연산을 한다.
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
using namespace std;
#define INF 1000000000
int main(void) {
freopen("inp.inp", "r", stdin);
freopen("out.out", "w", stdout);
vector<vector<int>> map;
vector<int> person;
int amount = 0;
cin >> amount;
for (int i = 0; i < amount; i++) {
vector<int> a;
map.push_back(a);
person.push_back(i);
for (int j = 0; j < amount; j++) {
int box;
cin >> box;
map[i].push_back(box);
}
}
vector<int> ind;
int k = amount/2;
for (int i = 0; i < k; i++) {
ind.push_back(1);
}
for (int i = 0; i < k; i++) {
ind.push_back(0);
}
int mins = INF;
sort(ind.begin(), ind.end());
do {
int A = 0;
int B = 0;
vector<int> alist;
vector<int> blist;
for (int i = 0; i < ind.size(); i++) {
if (ind[i] == 0)
alist.push_back(i);
else
blist.push_back(i);
}
for (int i = 0; i < alist.size(); i++) {
for (int j = i; j < alist.size(); j++) {
A += map[alist[i]][alist[j]];
A += map[alist[j]][alist[i]];
}
}
for (int i = 0; i < blist.size(); i++) {
for (int j = i; j < blist.size(); j++) {
B += map[blist[i]][blist[j]];
B += map[blist[j]][blist[i]];
}
}
int box = A - B;
if (box < 0)
box = -box;
if (mins >box) {
mins = box;
}
} while (next_permutation(ind.begin(), ind.end()));
cout << mins;
return 0;
}
https://www.acmicpc.net/problem/14889
14889번: 스타트와 링크
예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다.
www.acmicpc.net
728x90
'알고리즘 > 백준' 카테고리의 다른 글
2468. 안전 영역 (0) | 2020.07.30 |
---|---|
2667. 단지번호붙이기 (0) | 2020.07.30 |
14502 연구소 (0) | 2020.06.04 |
14501. 퇴사 (0) | 2020.06.04 |
14499. 주사위 굴리기 (0) | 2020.06.03 |