整数1-33中间,任意取6个数,它们加起来的和是100.
希望能得到有多少种组合,以及具体组合结果。
要求6个数不能重复。比如:17,17,17,17,17,15 这种不符合要求。

解决方案 »

  1.   

    已经在该帖给了答案
    http://community.csdn.net/Expert/topic/5017/5017256.xml?temp=.3018152
      

  2.   

    int num=0;
        for (int n1 = 1; n1 <= 14; n1++) {
          for (int n2 = n1+1; n2 <= 33; n2++) {
            for (int n3 = n2+1; n3 <= 33; n3++) {
              for (int n4 = n3+1; n4 <= 33; n4++) {
                for (int n5 = n4+1; n5 <= 33; n5++) {
                  for (int n6 = n5+1; n6 <= 33; n6++) {
                    if(n1+n2+n3+n4+n5+n6==100){
                      System.out.println(n1+"+"+n2+"+"+n3+"+"+n4+"+"+n5+"+"+n6+"=100");
                      num=num+1;
                      break;
                    }
                  }
                }
              }
            }
          }
        }
        System.out.println("总共"+num+"组数字");