c(n, r)我输入(4, 2)
意思是在1,2,3,4中任取2个.打印如下:
1,2
1,3
1,4
2,3
2,4
3,4我输入(5, 3)
意思是在1,2,3,4中任取2个.打印如下:
1,2,3
1,2,4
1,2,5
1,3,4
1,3,5
1,4,5
2,3,4
2,3,5
2,4,5
3,4,5打印顺序需要按上面的排序.
谢谢.

解决方案 »

  1.   


    public class CMN {
    private  int maxIndex = 4;// or 5; private int top = 26; private static int count = 0; private int[] s;  public static void main(String[] args) {
    CMN cmn = new CMN(2,4);
    cmn.DFS(0, 0);
    cmn = new CMN(3,5);
    cmn.DFS(0, 0);

    }
        public CMN(int max,int top){
         this.maxIndex = max;
         this.top = top ;
         s = new int[maxIndex];
        }
    public  void DFS(int now, int index) { for (int i = now; i < top; i++) {
    s[index] = i+1;
    if (index == maxIndex- 1) {
    show(s);
    count++;
    } else {
    DFS(i + 1, index + 1);
    }
    } } private static void show(int[] s) {
    for (int i = 0; i < s.length; i++) {
    System.out.print(s[i]);
    }
    System.out.println();
    }}
      

  2.   

    wizardblue(不死鱼) 是个强人.有机会多交流哈.