求排列求组合的实现

引用了@rogerwei的排列组合类

http://www.cnblogs.com/rogerwei/archive/2010/11/18/1880336.html

 

protected void Button1_Click(object sender, EventArgs e)
        {
            int r = Int32.Parse(intr.Text.Trim());
            int[]  arr=new int[6];
            int i;
            for (i = 0; i < arr.Length; i++)
            {
                arr[i] = i + 1;
            }

            //求排列
            List<int[]> lst_Permutation = web1.PermutationAndCombination<int>.GetPermutation(arr, r);
            Response.Write("-----------------------------共有"+lst_Permutation.Count+"种排列方式--------------------------------------------------<br/>");
            foreach (int[] str in lst_Permutation)
            {
                for (int j = 0; j < r; j++)
                {
                    Response.Write(str[j]);
                }
                Response.Write("<br/>");
            }
            Response.Write("-------------------------------------------------------------------<br/>");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int r = Int32.Parse(intr.Text.Trim());
            int[] arr = new int[6];
            int i;
            for (i = 0; i < arr.Length; i++)
            {
                arr[i] = i + 1;
            }
            //求组合
            List<int[]> lst_Combination = web1.PermutationAndCombination<int>.GetCombination(arr, r);
            Response.Write("-----------------------------共有" +  lst_Combination.Count + "种排列方式--------------------------------------------<br/>");
            foreach (int[] str in lst_Combination)
            {
                for (int j = 0; j < r; j++)
                {
                    Response.Write(str[j]);
                }
                Response.Write("<br/>");
            }
            Response.Write("-------------------------------------------------------------------<br/>");
        }

输出排列结果。

点击下载源码

posted @ 2012-06-22 20:22  逆水寒龙  阅读(329)  评论(0编辑  收藏  举报