0점은 항상 받을 수 있는 점수이다.
여기서 새로운 점수를 받을 때 마다 더해주며, 이전에 가능한 점수들 + 새로 받은 점수를 더해주어 가능한 점수를 체크한다.
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 32 33 34 35 36 37 38 39 40 41 42 | #include <stdio.h> #include <memory.h> #include <algorithm> using namespace std; int score[101]; int result[10001]; int n; int cnt; int main(void) { int T; setbuf(stdout, NULL); scanf("%d\n", &T); for (int testCase = 1; testCase <= T; testCase++) { scanf("%d", &n); memset(result, 0, sizeof(result)); memset(score, 0, sizeof(score)); cnt = 0; int max = 0; result[0] = 1; for (int i = 0; i < n; i++) { scanf("%d", &score[i]); max += score[i]; for (int j = max; j >=0; j--) { if (result[j] > 0) { result[j + score[i]]++; } } result[score[i]]++; } for (int i = 0; i < 10001; i++) { if (result[i] > 0) cnt++; } printf("#%d %d\n", testCase, cnt); } return 0; } | cs |