import java.util.ArrayList;
import java.util.List;

/**
 * Created by mtwtm on 2016/3/21.
 */
public class Helper {
    private class Permutation {
        private List<Integer> list;
        private boolean isIncrease;
        Permutation(int size, boolean isIncrease) {
            this.isIncrease = isIncrease;
            list = new ArrayList<>();
            int start = isIncrease ? 0 : size-1;
            int end = isIncrease ? size : -1;
            int increment = isIncrease ? 1 : -1;
            for(int i = start ; i != end ; i+=increment) {
                list.add(i);
            }
        }
        private int swapIndex(int comparingIndex) {
            int index = list.size()-1;
            boolean isSorted = isIncrease ? list.get(index) <= list.get(comparingIndex) : list.get(index) >= list.get(comparingIndex);
            while(isSorted) {
                index--;
                isSorted = isIncrease ? list.get(index) <= list.get(comparingIndex) : list.get(index) >= list.get(comparingIndex);
            }
            return index;
        }
        private int sortedCount() {
            int count = 1;
            boolean isSorted = isIncrease ? list.get(list.size()-1-count+1) <= list.get(list.size()-1-count) : list.get(list.size()-1-count+1) >= list.get(list.size()-1-count);
            while(isSorted) {
                count++;
                if(list.size()-1-count==-1) {
                    break;
                }
                isSorted = isIncrease ? list.get(list.size()-1-count+1) <= list.get(list.size()-1-count) : list.get(list.size()-1-count+1) >= list.get(list.size()-1-count);
            }
            return count;
        }
        public List<Integer> getNext() {
            int count = sortedCount();
            if(count==list.size()) {
                return null;
            } else {
                swap(list.size()-1-count, swapIndex(list.size()-1-count));
                if(count!=1) {
                    reverse(list.size()-count, list.size()-1);
                }
            }
            return getCurrent();
        }
        public void swap(int aIndex, int bIndex) {
            int temp = list.get(aIndex);
            list.set(aIndex, list.get(bIndex));
            list.set(bIndex, temp);
        }
        public void reverse(int aIndex, int bIndex) {
            int mid = (bIndex - aIndex + 1) / 2;
            for(int diff=0 ; diff<mid ; diff++) {
                swap(aIndex + diff , bIndex - diff);
            }
        }
        public List<Integer> getCurrent() {
            return list;
        }
    }
}

@@ -109,16 +109,985 @@
 elper %7B%0A
+    private class Combination %7B%0A        private int%5B%5D chosen;%0A        private int size;%0A        Combination(int n, int r) %7B%0A            chosen = new int%5Br%5D;%0A            size = n;%0A            for(int i=0 ; i%3Cr ; i++) %7B%0A                chosen%5Bi%5D = i;%0A            %7D%0A        %7D%0A%0A        public int%5B%5D get() %7B%0A            return chosen;%0A        %7D%0A%0A        public void next() %7B%0A            for(int i=chosen.length-1 ; i%3E=0 ; i--) %7B%0A                if(chosen%5Bi%5D!=size-(chosen.length-i)) %7B%0A                    chosen%5Bi%5D++;%0A                    for(int j=i+1 ; j%3Cchosen.length ; j++) %7B%0A                        chosen%5Bj%5D = chosen%5Bj-1%5D+1;%0A                    %7D%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A%0A        public boolean hasNext() %7B%0A            for(int i=chosen.length-1 ; i%3E=0 ; i--) %7B%0A                if(chosen%5Bi%5D!=size-(chosen.length-i)) %7B%0A                    return true;%0A                %7D%0A            %7D%0A            return false;%0A        %7D%0A    %7D%0A
     priv

Add Helper.Combination