728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com

import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tc=1;tc<=t;tc++) {
int n = sc.nextInt();
int l = sc.nextInt();
int dp[]=new int[l+1];
for(int i=0;i<n;i++) {
int score= sc.nextInt();
int cal = sc.nextInt();
for(int j=l;j>=cal;j--) {
dp[j]=Math.max(dp[j], dp[j-cal]+score);
}
}
System.out.println("#"+tc+" "+dp[l]);
}
}
}
평범한 배낭문제의 원리를 그대로 가져온 문제이다.
728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 증가하는 사탕 수열 (D3) (1) | 2024.10.03 |
|---|---|
| [SW Expert Academy] 0/1 Knapsack (D3) (1) | 2024.10.03 |
| [SW Expert Academy] 성공적인 공연 기획 (D3) (1) | 2024.10.03 |
| [SW Expert Academy] 항구에 들어오는 배 (D3) (0) | 2024.10.03 |
| [SW Expert Academy] 직사각형과 점 (D3) (0) | 2024.10.03 |