求一数组中某一范围内所有组合(不重复)C#

       /******************************************************************
        * *函数名:issame
        * *功  能:判断数组是否在另一个二维数组
        * *输  入:int[,] sArray, int m, int[] dArray, int n
        * *返  回:bool
        * *创建人:smallmuou
        * *日  期:2009-10-31
        *******************************************************************/
        private bool issame(int[,] sArray, int m, int[] dArray, int n)
        {
            bool result = false;
            int i, j, k;
            for (i = 0; i < m; i++)
            {
                k = 0;
                for (j = 0; j < n; j++)
                {
                    if (sArray[i, j] == dArray[j])
                        k++;
                }
                if (k == n)
                {
                    result = true;
                    break;
                }

            }
            return result;

        }

         /*****************************************************************************
        * *函数名:resort
        * *功  能:求所有组合
        * *输  入:int[] sArray,int arrayMax, int m, int[] dArray, int n, int sum, int max, int min,int MAX,int MIN
        * *返  回:void
        * *创建人:smallmuou
        * *日  期:2009-10-31
        ******************************************************************************/
        private void resort(int[] sArray,int arrayMax, int m, int[] dArray, int n, int sum, int max, int min,int MAX,int MIN)
        {

            int k;
            if (m <arrayMax)
            {
                sum += sArray[m];
                if (sum <= MAX && sum >= MIN)
                {
                    dArray[n] = sArray[m];
                    for (k = n + 1; k < dArrayMax; k++)
                        dArray[k] = 0;
                    if (issame(totleArray, totleArrayMax, dArray, dArrayMax))
                    {
                    }
                    else
                    {
                        for (k = 0; k < dArrayMax; k++)
                            totleArray[totleCount, k] = dArray[k];
                        totleCount++;
                    }

                    resort(sArray,arrayMax, m + 1, dArray, n + 1, sum, max - sArray[m], min - sArray[m],MAX,MIN);
                }
                else if (sum < MIN)
                {
                    dArray[n] = sArray[m];
                    for (k = n + 1; k < dArrayMax; k++)
                        dArray[k] = 0;
                    resort(sArray,arrayMax, m + 1, dArray, n + 1,sum, max - sArray[m], min - sArray[m],MAX,MIN);
                }
                else
                {
                    for (k = m + 1; k < arrayMax; k++)
                    {
                        if (sArray[m] == sArray[k])
                            m++;
                        else
                            break;
                    }
                }
                sum -= sArray[m];
                resort(sArray,arrayMax, m + 1, dArray, n,sum, max, min,MAX,MIN);
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值