File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+
4+ public class Main {
5+ public static void main (String [] args ) throws IOException {
6+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ String a = br. readLine();
8+ String b = br. readLine();
9+ String c = br. readLine();
10+
11+ int alength = a. length();
12+ int blength = b. length();
13+ int clength = c. length();
14+
15+ int [][][] dp = new int [alength + 1 ][blength + 1 ][clength + 1 ];
16+
17+ for (int i = 1 ; i <= alength; i++ ) {
18+ for (int j = 1 ; j <= blength; j++ ) {
19+ for (int k = 1 ; k <= clength; k++ ) {
20+ if (a. charAt(i - 1 ) == b. charAt(j - 1 ) && b. charAt(j - 1 ) == c. charAt(k - 1 )) {
21+ dp[i][j][k] = dp[i - 1 ][j - 1 ][k - 1 ] + 1 ;
22+ } else {
23+ dp[i][j][k] = Math . max(dp[i - 1 ][j][k],
24+ Math . max(dp[i][j - 1 ][k], dp[i][j][k - 1 ]));
25+ }
26+ }
27+ }
28+ }
29+
30+ System . out. println(dp[alength][blength][clength]);
31+ }
32+ }
33+ ```
You can’t perform that action at this time.
0 commit comments