728x90
※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다.
728x90
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
for (int tc = 1; tc <= T; tc++) {
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int[][] arr = new int[N][2];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
arr[i][0] = Integer.parseInt(st.nextToken()); // 부피
arr[i][1] = Integer.parseInt(st.nextToken()); // 가치
}
// dp
int[] dp = new int[K + 1];
for (int i = 0; i < N; i++) {
if(arr[i][0] > K) break;
for (int j = K - arr[i][0]; j >= 0; j--) {
dp[arr[i][0] + j] = Math.max(dp[arr[i][0] + j], dp[j] + arr[i][1]);
}
}
sb.append("#" + tc + " " + dp[K] + "\n");
}
System.out.println(sb);
}
}
728x90
'Problem Solving > SWEA' 카테고리의 다른 글
[SW Expert Academy, SWEA 3000] 중간값 구하기 (java) (0) | 2023.05.03 |
---|---|
[SW Expert Academy, SWEA 2930] 힙 (java) (1) | 2023.05.03 |
[SW Expert Academy, SWEA 1767] [SW Test 샘플문제] 프로세서 연결하기 (java) (0) | 2023.04.11 |
[SW Expert Academy, SWEA 1868] 파핑파핑 지뢰찾기 (java) (2) | 2023.04.10 |
[SW Expert Academy, SWEA 1248] [S/W 문제해결 응용] 3일차 - 공통조상 (java) (0) | 2023.04.09 |