public static int matrixChainOrder(int[] p,int[][] m,int[][] s){
		int n = p.length-1;
		for (int i = 0; i < n; i++) {
			m[i][i] = 0;
		}
		int j =0;
		int q =0;
		for(int l =2;l<=n;l++){
			for(int i=0;i<n-l+1;i++){
				j = i+l-1;
				m[i][j]=Integer.MAX_VALUE;
				for (int k = i; k <j; k++) {
					q = m[i][k]+m[k+1][j]+p[i]*p[k+1]*p[j+1];
					if (q<m[i][j]) {
						m[i][j]=q;
						s[i][j]=k;
					}
				}
			}
		}
		System.out.println("m[][]");
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < n; k++) {
				System.out.printf("%5d ",m[i][k]);
			}
			System.out.println();
		}
		System.out.println("s[][]");
		for (int i = 0; i < n; i++) {
			for (int
					k = 0; k < n; k++) {
				System.out.printf("%3d ",s[i][k]);
			}
			System.out.println();
		}
		return 0;
	}