Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01f25ec

Browse files
committed
[BOJ] 7579 앱_241016
1 parent df14e20 commit 01f25ec

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

‎BOJ/5001-10000번/YJ_7579.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import java.io.*;
2+
3+
public class YJ_7579 {
4+
static int[] memories;
5+
static int[] costs;
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String[] data = br.readLine().split("\\s");
9+
int N = Integer.parseInt(data[0]);
10+
int M = Integer.parseInt(data[1]);
11+
12+
String[] nM = br.readLine().split("\\s");
13+
String[] nC = br.readLine().split("\\s");
14+
memories = new int[N];
15+
costs = new int[N];
16+
for(int i=0; i<N; i++){
17+
memories[i] = Integer.parseInt(nM[i]);
18+
costs[i] = Integer.parseInt(nC[i]);
19+
}
20+
21+
System.out.println(getMinCostSum(N,M));
22+
}
23+
24+
//내생각: dp배열의 값을 최소비용으로 두고 접근(X)
25+
//1차원 dp배열을 최대비용으로 값을 메모리로 두고 접근(O)
26+
static int getMinCostSum(int N, int M){
27+
//dp[비용] = 메모리
28+
int[] dp = new int[10001]; //최대 비용의 총합
29+
30+
for(int app=0; app<N; app++){
31+
for(int c=10000; c>=costs[app]; c--){
32+
//최소 비용으로 가질수있는 최대메모리(최대라면 항상 메모리를 충족함)
33+
dp[c] = Math.max(dp[c], dp[c-costs[app]]+memories[app]);
34+
//현재 메모리 vs (현재 메모리를 추가한다면) 이전 상태의 메모리★ + 현재메모리
35+
}
36+
}
37+
38+
int result = 0;
39+
for(int i=0; i<dp.length; i++){
40+
//최소 비용부터 탐색해서 적정메모리 이상이 있는지 조회
41+
if(dp[i] >= M){
42+
result = i;
43+
break;
44+
}
45+
}
46+
47+
return result;
48+
}
49+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /