• 求排列求组合的实现


    引用了@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/>");
            }

    输出排列结果。

    点击下载源码

    -------------------------------------------------

    保持专注,只做一件事,做好这件事!@

    -------------------------------------------------

  • 相关阅读:
    MySql8安装使用中的一些注意
    如何在CentOS 8主机上安装Nginx Web服务器
    centos安装sqlserver
    VSCode快捷键
    C#中的委托
    Winform加载loading界面
    JayRock的一些用法:json and json rpc for .Net
    winform picturebox控件 定时让图片轮播
    sql server创建存储过程
    ftp上传单一文件示例
  • 原文地址:https://www.cnblogs.com/24la/p/2558912.html
Copyright © 2020-2023  润新知