2817. 부분 수열의 합
문제 출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7IzvG6EksDFAXB
D3의 정답률 40% 미만의 문제 수준이 좀 이상한거 같아요.
너무 쉬운거 같은데;;
2018년 3월 15일 import java.util.Scanner; public class Q2817 {
static int result, size, resultValue; static int[] values;
public static void main(String[] args) { Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt(); for (int i = 0; i < testCase; i++) { result = 0; size = sc.nextInt(); resultValue = sc.nextInt(); values = new int[size];
for (int j = 0; j < size; j++) { values[j] = sc.nextInt(); } solution(0, 0); System.out.println("#" + (i+1) + " " + result); } }
static void solution(int position, int nowValue) { for (int i = position; i < size; i++) { int tempValue = nowValue + values[i]; if (tempValue < resultValue) { solution (i+1, tempValue); } else if (tempValue == resultValue) { result += 1; } } } } |