동전 문제와 동일하다.
맨 처음은 문제가 없으므로 0점만 가능하다. (a[0] = 1)
그 다음에는 배점을 입력받으면서 가능한 경우의 수를 배열에 기록한다.
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 | #include <iostream> using namespace std; int t, n; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> t; for (int tc = 1; tc <= t; ++tc) { int a[10101] = { 0, }; cin >> n; int r = 0, temp = 0, ans = 0; a[0] = 1; while (n--) { cin >> temp; r += temp; for (int i = r; i >= temp; --i) a[i] |= a[i - temp]; } for (int i = 0; i <= r; ++i) ans += a[i]; cout << "#" << tc << " " << ans << '\n'; } return 0; } | cs |
'SWEA' 카테고리의 다른 글
1251. 하나로 (0) | 2018.08.29 |
---|---|
2105. 디저트 카페 (0) | 2018.08.29 |
5357. 터널 속의 기차 (0) | 2018.08.29 |
5356. 의석이의 세로로 말해요 (0) | 2018.08.29 |
5299. 아름다운 균일 수 (0) | 2018.08.21 |