티스토리 뷰

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWHPkqBqAEsDFAUn



#include <iostream>

#include <algorithm>
using namespace std;
 
#define MAX_N 101
#define MAX_M 10000
 
int i, j, N, result;
int a[MAX_N], check[MAX_M];
 
void input()
{
    cin >> N;
    for (i = 1;i <= N;i++) cin >> a[i];
    for (i = 0;i <= MAX_M;i++) check[i] = 0;
    check[0] = 1;
}
 
void cal()
{
    result = 0;
    for (i = 1;i <= N;i++) for (j = MAX_M;j >= 0;j--)
    {
        if (check[j] > 0 && j+a[i]<=10000)
        {
            check[j+a[i]] += 1;
        }
    }
 
    for (i = 0;i <= MAX_M;i++)
    {
        if (check[i] >0) result += 1;
    }
}
 
 
int main()
{
    int T, t; t = 1;
    cin >> T;
    while (T--)
    {
        input(); cal();
        cout << "#" << t << " " << result << endl;
        t++;
    }
}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1949] 등산로 조정  (0) 2018.07.23
[SWEA 4014] 활주로 건설  (0) 2018.07.23
[SWEA 4013] 특이한 자석  (0) 2018.07.23
[SWEA 1952] 수영장  (0) 2018.07.23
[SWEA 1767] 프로세서 연결하기  (0) 2018.07.23
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함