2303 숫자게임
2019. 9. 13. 20:51ㆍ알고리즘/백준
브루트포스 문제
문제: https://www.acmicpc.net/problem/1268
깃허브주소: https://github.com/surinoel/boj/blob/master/2303.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#define max(n, m) n > m ? n : m | |
int a[5]; | |
int tans; | |
void go(int idx, int cnt, int sum) { | |
if (cnt == 3) { | |
tans = max(tans, sum % 10); | |
return; | |
} | |
if (idx == 5) { | |
return; | |
} | |
go(idx + 1, cnt + 1, sum + a[idx]); | |
go(idx + 1, cnt, sum); | |
} | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
int ans = -1; | |
int aidx; | |
for (int i = 0; i < n; i++) { | |
for (int j = 0; j < 5; j++) { | |
cin >> a[j]; | |
} | |
tans = -1; | |
go(0, 0, 0); | |
if (ans == -1 || tans >= ans) { | |
ans = tans; | |
aidx = i + 1; | |
} | |
} | |
cout << aidx << '\n'; | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
2304 창고 다각형 (0) | 2019.09.13 |
---|---|
1268 임시 반장 정하기 (0) | 2019.09.13 |
14226 이모티콘 (0) | 2019.09.07 |
4963 섬의 개수 (0) | 2019.09.07 |
2667 단지번호 붙이기 (0) | 2019.09.06 |