public static boolean wordBreak(String s, Set<String> dict) {
    	int len = s.length();
    	boolean[] iswordbreak = new boolean[len + 1];
    	iswordbreak[len] = true;
    	for (int i = len - 1; i >= 0; i--) {
    		for (int j = i; j < len; j++) {
    			String word = s.substring(i, j + 1);
    			if (iswordbreak[j + 1] && dict.contains(word)) {
    				iswordbreak[i] = true;
    				break;
    			}
    		}
    	}
        return iswordbreak[0];
    }