Skip to content

Commit d0b338d

Browse files
authored
Merge pull request #1886 from AlgorithmWithGod/Ukj0ng
[20260205] BOJ / G3 / 유전자 / 한종욱
2 parents 9c0d065 + b5f5add commit d0b338d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```
2+
import java.io.*;
3+
4+
public class Main {
5+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
7+
private static int[][] dp;
8+
9+
public static void main(String[] args) throws IOException {
10+
init();
11+
12+
bw.write(dp[1][dp[0].length-2] + "\n");
13+
bw.flush();
14+
bw.close();
15+
br.close();
16+
}
17+
18+
private static void init() throws IOException {
19+
char[] input = br.readLine().toCharArray();
20+
21+
dp = new int[input.length+2][input.length+2];
22+
23+
int left = 0;
24+
int right = 1;
25+
26+
while (left <= input.length-2) {
27+
if (input[left] == 'a' && input[right] == 't') dp[left+1][right+1] = 2;
28+
if (input[left] == 'g' && input[right] == 'c') dp[left+1][right+1] = 2;
29+
left++;
30+
right++;
31+
}
32+
33+
34+
for (int len = 3; len <= input.length; len++) {
35+
for (int i = 1; i+len-1 <= input.length; i++) {
36+
if ((input[i-1] == 'a' && input[i-2+len] == 't')
37+
|| (input[i-1] == 'g' && input[i-2+len] == 'c')) {
38+
dp[i][i+len-1] = dp[i+1][i+len-2]+2;
39+
}
40+
for (int j = i; j < i+len-1; j++) {
41+
dp[i][i+len-1] = Math.max(dp[i][i+len-1], dp[i][j] + dp[j+1][i+len-1]);
42+
}
43+
}
44+
}
45+
}
46+
}
47+
```

0 commit comments

Comments
 (0)