public int minCut(String s) {

		if (s == null || s.length() < 2)
			return 0;
		int n = s.length();
		int[] D = new int[n + 1]; // dp for cut
		boolean[][] P = new boolean[n][n]; // dp for palindrome
		for (int i = 0; i <= n; i++) {
			D[i] = n - i;			// initialize to maxium cut
		}					
		for (int i = n - 1; i >= 0; i--) {
			for (int j = i; j < n; j++) {
				if (s.charAt(i) == s.charAt(j)
						&& (j - i < 2 || P[i + 1][j - 1])) {
					P[i][j] = true;
					D[i] = Math.min(D[i], D[j + 1] + 1);
				}
			}
		}

		return D[0] - 1;

	}