Skip to content

Commit 89d83df

Browse files
committed
1026
1 parent 2b9ccfc commit 89d83df

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
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/BOJ1182/BOJ1182.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/BOJ1182/src/Main.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
17
public class Main {
2-
public static void main(String[] args) {
3-
System.out.println("Hello world!");
8+
static int N;
9+
static int S;
10+
static int[] num;
11+
12+
13+
static int count = 0;
14+
15+
public static void main(String[] args) throws IOException {
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
N = Integer.parseInt(st.nextToken());
19+
S = Integer.parseInt(st.nextToken());
20+
num = new int[N];
21+
st = new StringTokenizer(br.readLine());
22+
int i = 0;
23+
while (st.hasMoreTokens()) {
24+
num[i] = Integer.parseInt(st.nextToken());
25+
i++;
26+
}
27+
28+
DFS(0, 0);
29+
if(S==0){
30+
System.out.println(count-1);
31+
}else{
32+
System.out.println(count);
33+
}
34+
35+
36+
37+
}
38+
39+
private static void DFS(int sum, int r) {
40+
41+
if (N == r) {
42+
if (sum == S) {
43+
count++;
44+
}
45+
return;
46+
}
47+
48+
DFS(sum + num[r], r + 1) ;
49+
DFS(sum , r + 1) ;
50+
451
}
552
}

0 commit comments

Comments
 (0)