昨天我去面试,公司给了我这样一个问题:36个数每一次只能选7个数,如1、2、3、4...34、35、36。1、2、3、4、5、6、7和1、3、2、4、5、6、7是两种不同的算法。请问有多少种算法?我写不出来。请各位大侠帮帮我

解决方案 »

  1.   

    faint,
    得看数字是否可以重复
      

  2.   

    http://community.csdn.net/Expert/topic/5356/5356205.xml?temp=.4842951
      

  3.   

    program Project2;{$APPTYPE CONSOLE}uses
      SysUtils, Windows;const
      Max                                   = 36;
    var
      I1, I2, I3, I4, I5, I6, I7            : Integer;
      Count                                 : Integer;
    begin
      Count := 0;
      for I1 := 1 to Max - 6 do
        for I2 := I1+1 to Max - 5 do
          for I3 := I2+1 to Max - 4 do
            for I4 := I3+1 to Max - 3 do
              for I5 := I4+1 to Max - 2 do
                for I6 := I5+1 to Max - 1 do
                  for I7 := I6+1 to Max  do
                  begin
                    Inc(Count);
                    {
                    不输出到屏幕只有300毫秒
                    输出到屏幕非常费时,最好不要输出.等死你啊
                    }
                    //writeln(Format('%.8d: %.2d;%.2d;%.2d;%.2d;%.2d;%.2d;%.2d',
                    //   [Count, I1,I2,I3,I4,I5,I6,I7]));
                  end;   MessageBox(0,PChar(Format('共%d种组合!',[Count])),'', MB_OK or MB_ICONINFORMATION);
    end.