Skip to content

Commit b9e65ca

Browse files
committed
1010
1 parent 626b93f commit b9e65ca

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BOJ/silver/BOJ1495/BOJ1495.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

BOJ/silver/BOJ1495/src/Main.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class Main {
7+
static int[] volume;
8+
static int maxv = -1;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
int N = Integer.parseInt(st.nextToken());
14+
int S = Integer.parseInt(st.nextToken());
15+
int M = Integer.parseInt(st.nextToken());
16+
volume = new int[N+1];
17+
18+
st = new StringTokenizer(br.readLine());
19+
int c = 1;
20+
while (st.hasMoreTokens()) {
21+
volume[c] = Integer.parseInt(st.nextToken());
22+
c++;
23+
}
24+
int[][] dp = new int[N + 1][M + 1];
25+
dp[0][S]=1;
26+
for (int i = 1; i < N+1; i++) {
27+
for(int j=0; j<M+1;j++){
28+
if(dp[i-1][j]==1){
29+
if(j+volume[i]<=M){
30+
dp[i][j+volume[i]]=1;
31+
}
32+
if(j-volume[i]>=0){
33+
dp[i][j-volume[i]]=1;
34+
}
35+
}
36+
37+
}
38+
39+
}
40+
for(int i=0; i<M+1;i++){
41+
if(dp[N][i]==1){
42+
maxv = Math.max(maxv, i);
43+
44+
}
45+
}
46+
47+
System.out.println(maxv);
48+
49+
}
50+
51+
52+
53+
}

0 commit comments

Comments
 (0)