public static boolean wordBreakDPOpt(String s, Set<String> dict) {
		
		if (s == null || s.length() == 0) {
			if (dict == null || dict.size() == 0) {
				return true;
			} 
		} 
		
		int len = s.length();
		boolean[] canSegment = new boolean[len + 1];
		int maxLen = getMaxLength(dict);
		canSegment[0] = true;
		for ( int i = 1; i <= s.length(); i++) {
			canSegment[i] = false;
			for (int j = 1; j <= maxLen && j <= i; j++) {
				if (canSegment[i-j] == false) {
					continue;
				}
				String word = s.substring(i-j, i);
				if (dict.contains(word)) {
					canSegment[i] = true;
					break;
				}
			}
		}
		return canSegment[len];
	}