File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+ import java.util.Arrays ;
6+ import java.util.HashSet ;
7+ import java.util.StringTokenizer ;
8+
9+ public class Main {
10+
11+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
12+ static char [][] words;
13+ static int [][][] dp;
14+ static int ans = 0 ;
15+
16+
17+ public static void main (String [] args ) throws IOException {
18+
19+ init();
20+ process();
21+ print();
22+
23+ }
24+
25+ private static void init () throws IOException {
26+ words = new char [3 ][];
27+ for (int i = 0 ; i < 3 ; i++ ) {
28+ words[i] = br. readLine(). toCharArray();
29+ }
30+ dp = new int [words[0 ].length+1][words[1 ].length+1][words[2 ].length+1];
31+ }
32+
33+ private static void process () throws IOException {
34+ for (int i = 1 ; i <= words[0 ]. length; i++ ) {
35+ for (int j = 1 ; j <= words[1 ]. length; j++ ) {
36+ for (int k = 1 ; k <= words[2 ]. length; k++ ) {
37+ if (words[0 ][i- 1 ] == words[1 ][j- 1 ] && words[1 ][j- 1 ] == words[2 ][k- 1 ]) {
38+ dp[i][j][k] = dp[i- 1 ][j- 1 ][k- 1 ]+ 1 ;
39+ } else {
40+ dp[i][j][k] = Math . max(Math . max(dp[i- 1 ][j][k], dp[i][j- 1 ][k]), dp[i][j][k- 1 ]);
41+ }
42+ }
43+ }
44+ }
45+ }
46+
47+ private static void print () {
48+ System . out. println(dp[words[0 ]. length][words[1 ]. length][words[2 ]. length]);
49+ }
50+
51+ }
52+ ```
You can’t perform that action at this time.
0 commit comments