zoukankan      html  css  js  c++  java
  • 33选6算法:M个数N个为一组,无重复的排列组合

            private void button1_Click(object sender, EventArgs e)
            {
                int nCnt = 0;
                List nNumList = new List();
                for (int i = 0; i < cblNumList.Items.Count; i++)
                {
                    if (cblNumList.GetItemChecked(i))
                    {
                        nNumList.Add(Convert.ToInt32(cblNumList.Items[i].ToString()));
                    }
                }
                System.Text.StringBuilder sbResult = new StringBuilder();
                int nLast = nNumList.Count;
                for (int i1 = 0; i1 < nLast-5; i1++)
                {
                    for (int i2 = 0; i2 < nLast - 4; i2++)
                    {
                        if (i2 == i1) continue;
                        for (int i3 = 0; i3 < nLast - 3; i3++)
                        {
                            if (i3 == i2 || i3 == i1) continue;
                            for (int i4 = 0; i4 < nLast - 2; i4++)
                            {
                                if (i4 == i3 || i4 == i2 || i4 == i1) continue;
                                for (int i5 = 0; i5 < nLast - 1; i5++)
                                {
                                    if (i5 == i4 || i5 == i3 || i5 == i2 || i5 == i1) continue;
                                    for (int i6 = 0; i6 < nLast; i6++)
                                    {
                                        if (i6 == i5 || i6 == i4 || i6 == i3 || i6 == i2 || i6 == i1) continue;
                                        if (nNumList[i1] > nNumList[i2] || nNumList[i2] > nNumList[i3] || nNumList[i3] > nNumList[i4] || nNumList[i4] > nNumList[i5] || nNumList[i5] > nNumList[i6]) continue;
                                        sbResult.Append("
    " + nNumList[i1].ToString() + " " + nNumList[i2].ToString() + " " + nNumList[i3].ToString() + " " + nNumList[i4].ToString() + " " + nNumList[i5].ToString() + " " + nNumList[i6].ToString());
                                        nCnt += 1;
                                    }
                                }
                            }
                        }
                    }
                }
                tbResult.Text = sbResult.ToString();
                //lblMessage.Text = nLast + " 个随机数字;共有 " + nCnt + " 条记录";
            }
    
  • 相关阅读:
    利用nginx实现负载均衡和动静分离
    Nginx动静分离实现
    php中session 入库的实现
    php文字水印和php图片水印实现代码(二种加水印方法)
    采集图片水印添加
    [安全]PHP能引起安全的函数
    [安全]服务器安全之 PHP权限目录
    Centos下安装git的web服务器
    Centos下抓包
    UVA 10795
  • 原文地址:https://www.cnblogs.com/changweihua/p/3361597.html
Copyright © 2011-2022 走看看