public static int optimalBst(int[] p,int[] q,int[][] e,int[][] w,int[][] root){
		int n = p.length;
		for (int i = 1; i <= n; i++) {
			e[i][i-1] = q[i-1];
			w[i][i-1] = q[i-1];
		}
		int j =0;
		int t =0;
		for(int l =1;l<=n;l++){
			for(int i=1;i<n-l+1;i++){
				j = i+l-1;
				e[i][j]=Integer.MAX_VALUE;
				w[i][j]=w[i][j-1]+p[j]+q[j];
				for (int r = i; r <=j; r++) {
					t = e[i][r-1]+e[r+1][j]+w[i][j];
					if (t<e[i][j]) {
						e[i][j]=t;
						root[i][j]=r;
					}
				}
			}
		}
		System.out.println("e[][]");
		for (int i = 0; i < n+1; i++) {
			for (int k = 0; k < n; k++) {
				System.out.printf("%5d ",e[i][k]);
			}
			System.out.println();
		}
		System.out.println("w[][]");
		for (int i = 0; i < n+1; i++) {
			for (int
					k = 0; k < n; k++) {
				System.out.printf("%3d ",w[i][k]);
			}
			System.out.println();
		}
		System.out.println("root[][]");
		for (int i = 0; i < n; i++) {
			for (int
					k = 0; k < n; k++) {
				System.out.printf("%3d ",root[i][k]);
			}
			System.out.println();
		}
		return 0;
	}