Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- CTS #CTS 이관 #SAP #ABAP
- ZPL
- FOR ALL ENTRIES IN
- transporting
- BOJ_Gold
- using value
- changing value
- ABAP
- READ TABLE
- APPENDING CORRESPONDING
- SAP
- DP - 무한배낭(순서)
- batch job
- 필드카탈로그
- 날짜 계산 함수
- MONAT_F4
- Data Browser
- NEW-PAGE PRINT ON
- qfieldname
- Dictionary Search Help
- APPENDING
- Union-Find
- SM36
- java
- boole_d
- DP - 무한배낭
- DP - 유한배낭
- ALV Output Setting
- cfieldname
- SAP GUI
Archives
- Today
- Total
Jin's Library
[Gold Ⅴ] 12865 - 평범한 배낭 본문
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class BOJ_12865 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int weight = Integer.parseInt(st.nextToken());
int[] W = new int[N];
int[] V = new int[N];
int[] dp = new int[weight+1];
for(int i = 0; i < N ; i++){
st = new StringTokenizer(br.readLine());
W[i] = Integer.parseInt(st.nextToken());
V[i] = Integer.parseInt(st.nextToken());
}
for(int i = 0; i < N; i++){
int a = W[i];
int b = V[i];
// for(int j = a; j <= weight; j++)
for(int j = weight; j >= a; j--)
dp[j] = Math.max(dp[j], dp[j-a] + b);
}
System.out.println(Arrays.stream(dp).max().getAsInt());
// System.out.println(Arrays.toString(dp));
}
}
// 각 Weight 당 최대의 Value를 뽑아내야 한다.'Algorithm - Java > BOJ - Gold' 카테고리의 다른 글
| [Gold Ⅴ] 15486 - 퇴사 2 (0) | 2025.10.24 |
|---|---|
| [Gold Ⅳ] 2293 - 동전 1 (0) | 2025.10.20 |
| [Gold Ⅴ] 1931 - 회의실 배정 (0) | 2025.10.17 |
| [Gold Ⅳ] 1043 - 거짓말 (0) | 2025.10.02 |
| [Gold Ⅱ] 10775 - 공항 (0) | 2025.10.01 |