티스토리 뷰
출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5V1SYKAaUDFAWu
#include<iostream>
#include<algorithm>using namespace std; int D, W, K;int map[14][21];int cpy[14][21];int res; bool Check(){ bool isOk; int cnt; for (int j = 1; j <= W; j++){ cnt = 1; isOk = false; for (int i = 2; i <= D; i++){ if (map[i][j] == map[i - 1][j]) cnt++; else cnt = 1; if (cnt >= K) { isOk = true; break; } } if (!isOk) return false; } return true;} void Solve(int idx, int val, int cnt){ for (int i = 1; i <= W; i++) map[idx][i] = val; for (int i = idx + 1; i <= D; i++) Solve(i, val, cnt + 1); if (Check()) res = min(res, cnt); for (int i = 1; i <= W; i++) map[idx][i] = cpy[idx][i];} int main(){ int T; cin >> T; for (int t = 1; t <= T; t++){ cin >> D >> W >> K; for (int i = 1; i <= D; i++){ for (int j = 1; j <= W; j++){ cin >> map[i][j]; cpy[i][j] = map[i][j]; } } res = 999; if (Check()) res = 0; else{ Solve(0, 0, 0); Solve(0, 1, 0); } cout << "#" << t << " "; cout << res << endl; }}'알고리즘 > SWEA' 카테고리의 다른 글
| [SWEA 2115] 벌꿀채취 (0) | 2018.07.23 |
|---|---|
| [SWEA 4008] 숫자 만들기 (0) | 2018.07.23 |
| [SWEA 2105] 디저트 카페 (0) | 2018.07.23 |
| [SWEA 1949] 등산로 조정 (0) | 2018.07.23 |
| [SWEA 4014] 활주로 건설 (0) | 2018.07.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 알고리즘
- hackerrank
- 미세먼지 안녕!
- 시간 복잡도
- 게리맨더링 2
- 연구소 3
- DP
- DFS
- 17143
- 삼성
- string
- 2018 카카오 블라인드 채용
- 17144
- 팁
- 17142
- 입출력
- 트렌드
- STL
- 17140
- SWEA
- SW Expert Academy
- 역량 테스트
- 백준
- 17837
- 새로운 게임 2
- 17779
- 이차원 배열과 연산
- scanf
- 2018 KAKAO BLIND RECRUITMENT
- boj
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함