Import Java. util. arrays; public class besttree {public int N; Public double W [] []; Public double C [] []; Public int R [] []; Public besttree (int n) {c = new double [n + 2] [n + 1]; W = new double [n + 2] [n + 1]; R = new int [n + 2] [n + 1];} public void optionbinarysearch (int n, Double P [], double Q []) {for (INT I = 1; I <= N; I ++) {C [I] [I-1] = 0; W [I] [I-1] = Q [I-1];} public void optionbinarysearch (int n, Double P [], double Q []) {for (INT I = 1; I <= N; I ++) {C [I] [I-1] = 0; W [I] [I-1] = Q [I-1];} for (int K = N; k> = 1; k --) {for (INT I = 1; I <= K; I ++) {Int J = I-K + 5; W [I] [J] = W [I] [J-1] + P [J] + Q [J]; // when I <= J, C [I, j) = W (I, j) + min {C (I, k-1) + C (k + 1, j)} C [I] [J] = W [I] [J] + C [I] [I-1] + C [I + 1] [J]; R [I] [J] = I; for (int m = I + 1; m <= J; m ++) {double T = W [I] [J] + C [I] [s-1] + C [M + 1] [J]; If (float) T <(float) c [I] [J]) {// compare to minimize the value of C [I] [J] C [I] [J] = T; R [I] [J] = m ;}}} public void bestsolution (int r [] [], int I, Int J) {if (I <= J) {system. out. the root of println ("S" + I + "and S" + J + "is:" + "S" + R [I] [J]); bestsolution (r, i, R [I] [J]-1); bestsolution (R, R [I] [J] + 1, J );}} public static void main (string [] ARGs) {Double P [] = {0, 0.15, 0.1, 0.05, 0.1}; double Q [] = {0.2, 0.05, 0.05, 0.05, 0.05, 0.1}; besttree tree = new besttree (5); tree. n = 5; tree. optionbinarysearch (5, p, q); For (INT I = 1; I <= 5; I ++) {system. out. println (arrays. tostring (tree. R [I]);} tree. bestsolution (tree. r, 1, 5 );}}