如题用C# 编写代码 26个英文字母加上10个数字,按8位来排,不能重复,有多少种组合方式?然后把他们全部显示出来,谢谢各位

解决方案 »

  1.   

    笔误,排列是A(36,8)[以前是P(36,8)],组合是C(36,8).A(n,m)=n(n-1)(n-2)……(n-m+1)= n!/(n-m)! 此外规定0!=1
    C(n,m)=A(n,m)/m!=n!/((n-m)!*m!)
      

  2.   

    把问题的规模缩小一下,可以求解并显示。你的问题规模太大了:
        class Program
        {
            const string charStr = "012345678";
            const int size = 5;
            static int count = 0;
            static void Main(string[] args)
            {            Ass(new char[size], 0, charStr.ToList());
                Console.WriteLine("Count={0}", count);
                Console.ReadLine();
            }        static void Ass(char[] temp, int pos, List<char> lst)
            {
                for (int i = 0; i < lst.Count; i++)
                {
                    temp[pos] = lst[i];
                    var smlst = new List<char>(lst);
                    smlst.RemoveAt(i);
                    if (pos == size - 1)
                    {
                        Console.WriteLine(new string(temp));
                        count++;
                    }
                    else
                    {
                        Ass(temp, pos + 1, smlst);
                    }
                }
            }
        }