Skip to content

Commit 8a1bb8f

Browse files
authored
Merge pull request #1577 from AlgorithmWithGod/LiiNi-coder
[20251203] BOJ / G5 / 문자열 판별 / 이인희
2 parents 00f9db2 + 2fea2ce commit 8a1bb8f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String S = br.readLine();
9+
int N = Integer.parseInt(br.readLine());
10+
Set<String> dict = new HashSet<>();
11+
12+
for(int i = 0; i < N; i++){
13+
dict.add(br.readLine());
14+
}
15+
16+
int size = S.length();
17+
boolean[] dp = new boolean[size + 1];
18+
dp[size] = true;
19+
20+
for(int i = size - 1; i >= 0; i--){
21+
for(int j = i + 1; j <= size; j++){
22+
if(dp[j] && dict.contains(S.substring(i, j))){
23+
dp[i] = true;
24+
break;
25+
}
26+
}
27+
}
28+
System.out.println(dp[0] ? 1 : 0);
29+
}
30+
}
31+
```

0 commit comments

Comments
 (0)