반응형
링크
https://swexpertacademy.com/main/main.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
1. 해결방법
처음에 for문을 2번 돌려서 해결하려 했지만 오류가 있었고 다른 분의 코드를 참고하였다
점수가 3가지가 입력되었다면 1번부터 가능한 모든 점수를 구하고, 다음번에 2번째 점수를 1번째 경우에 수에 모두 더하고,,,, 이런 방식으로 해결하였다
2. 코드
#include <iostream>
#include <stdio.h>
#include<string.h>
using namespace std;
int total = 0;
int num = 0;
int ary[100];
int result[10001];
int temp;
int cnt;
int main()
{
scanf("%d", &total);
for (int i = 0; i < total; i++) {
memset(result, 0, sizeof(result));
memset(ary, 0, sizeof(ary));
result[0] = 1;
cnt = 0; temp = 0;
scanf("%d", &num);
for (int j = 0; j < num; j++) {
scanf("%d", &ary[j]);
temp += ary[j];
for (int n = temp; n >= 0; n--) {
if (result[n]) {
result[n + ary[j]]++;
}
}
result[ary[j]]++;
}
for (int i = 0; i < 10001; i++) {
if (result[i] > 0)
cnt++;
}
printf("#%d %d\n", i+1, cnt);
}
return 0;
}
반응형
'코딩테스트 > SW expert' 카테고리의 다른 글
[SW Expert] #1244 S/W 문제해결 응용 2일차 - 최대 상금 (0) | 2019.11.27 |
---|---|
[SW Expert] #2806 N-Queen (0) | 2019.11.22 |
[SW Expert] #1249 S/W 문제해결 응용 4일차 - 보급로 (0) | 2019.11.07 |
[SW Expert] #2819 격자판의 숫자 이어붙이기 (0) | 2019.11.04 |
[SW Expert] #1206 S/W 문제해결 기본 1일차 - View (0) | 2019.11.01 |