当前位置:编程学习 > C#/ASP.NET >>

求大侠帮忙易做图的组合算法

如题 以双色球为例    红球 1到33共33个号 篮球1到16共16个号  用什么方法能够快速的组合 红球六个数加篮球一个数是一组, ,有几百万个组合呢。怎么能够快速的把所有有可能的组合给显示出来呢
红球 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
篮球  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16

红球1,2,3,4,5,6+篮球2   这样算一组 --------------------编程问答-------------------- 只弄7星
--------------------编程问答-------------------- 多个For进行嵌套不就行了……
然后用If判断位数之间是否有重复……如果重复就Break。 --------------------编程问答-------------------- 除非你的CPU很牛X,现在也有GPU编程,也可以用GPU进行运算。
我在我的电脑上进行质数运算到百万需要15分钟或者更长……
我正在VS写这个代码,等会发来…… --------------------编程问答--------------------             int i1, i2, i3, i4, i5, i6, j;
            for (i1 = 1; i1 <= 26; i1++)
            {
                for (i2 = 1; i2 <= 26; i2++)
                {
                    if (i2 == i1)
                    {
                        break;
                    }
                    for (i3 = 1; i3 <= 26; i3++)
                    {
                        if (i3 == i1 || i3 == i2)
                        {
                            break;
                        }
                        for (i4 = 1; i4 <= 26; i4++)
                        {
                            if (i4 == i1 || i4 == i2 || i4 == i3)
                            {
                                break;
                            }
                            for (i5 = 1; i5 <= 26; i5++)
                            {
                                if (i5 == i1 || i5 == i2 || i5 == i3 || i5 == i4)
                                {
                                    break;
                                }
                                for (i6 = 1; i6 <= 26; i6++)
                                {
                                    if (i6 == i1 || i6 == i2 || i6 == i3 || i6 == i4 || i6 == i5)
                                    {
                                        break;
                                    }
                                    for (j = 1; j <= 16; j++)
                                    {
                                        //这里写输出代码,输出i1至i6和j。
                                    }
                                }
                            }
                        }
                    }
                }
            }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,