티스토리 뷰
출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIeUtVakTMDFAVH
#include <iostream>
#include <algorithm>#include <vector>using namespace std;int N, result, total;int map[16][16];bool check[16];int cal(vector<int> &v){ int tmp = 0; for (int i = 0; i < total;i++) for (int j = 0; j < total; j++) {if (i == j) continue; tmp += map[v[i]][v[j]];} return tmp;}int sin(){ vector <int> a; vector <int> b; for (int i = 0; i < N; i++) { if (check[i]) a.push_back(i); else b.push_back(i); } return abs(cal(a) - cal(b));}void dfs(int wh, int cnt){ if (cnt == total) { result = min(result, sin()); return; } for (int i = wh; i < N; i++) if (!check[i]) { check[i] = true; dfs(i, cnt + 1); check[i] = false; }}int main(){ int T; int tc = 1; cin >> T; while (T--) { cin >> N; for (int i = 0;i < N;i++) for (int j = 0;j < N; j++) cin >> map[i][j]; total = N / 2; result = 2e9; check[0] = true; dfs(1, 1); cout <<"#" << tc++ << " " << result << endl; } return 0;}'알고리즘 > SWEA' 카테고리의 다른 글
| [SWEA 4747] 사막에서 만난 지니 (0) | 2018.07.26 |
|---|---|
| [SWEA 2117] 홈 방범 서비스 (0) | 2018.07.23 |
| [SWEA 2115] 벌꿀채취 (0) | 2018.07.23 |
| [SWEA 4008] 숫자 만들기 (0) | 2018.07.23 |
| [SWEA 2112] 보호 필름 (2) | 2018.07.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 이차원 배열과 연산
- 백준
- 역량 테스트
- 트렌드
- 연구소 3
- 17837
- 17144
- 미세먼지 안녕!
- boj
- SW Expert Academy
- DP
- 삼성
- 17142
- 2018 KAKAO BLIND RECRUITMENT
- 게리맨더링 2
- 새로운 게임 2
- SWEA
- 17143
- 알고리즘
- string
- STL
- scanf
- 17779
- 팁
- 입출력
- 17140
- hackerrank
- 시간 복잡도
- 2018 카카오 블라인드 채용
- DFS
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함