如何对组合进行计算? [英] How to perform calculations on combinations?

查看:61
本文介绍了如何对组合进行计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要找到组合,然后通过替换值来计算所得组合的值..

Hi all,

I need to find combinations, and calculate values for the resultant combinations by substituting values..

string[] str=new string[]{"A","B","C","D"};
double[] vals=new double[]{1,3,6,9};


A = 1;
B = 3;
C = 6;
D = 9

说N = 4,M = 3;//N和M是动态值
N-M + 1 = 2;

所以我想找到N-M + 1值的str的组合,即4C2 =6.
我得到6种组合.
AB
AC
公元
BC
BD
CD ..

最后我想计算&将组合值存储在另一个Array中.

我使用下面的代码,它适用于N = 4,M = 2


A=1;
B=3;
C=6;
D=9

Say N=4,M=3;// N and M are Dynamic values
N-M+1=2;

so i want to find combinations for str with N-M+1 Value ie 4C2 = 6.
i am getting 6 Combinations.
AB
AC
AD
BC
BD
CD..

finally i want to calculate & store the combination values in another Array..

I used below code, it works for N=4,M=2

for (int j = 0; j < factval; j++)//factval,faval is FactorialValue ie 4C3 Combination Value
{
   for (int k = 0; k < PFDdu.Length; k++)//PFDdu is str Length
   {
       if (!string.IsNullOrEmpty(PFDdu[(k + 1) % PFDdu.Length].ToString()))
       {
          if (j != (k + 1) % PFDdu.Length)
          {
              faval[j] = faval[j] * PFDdu[(k + 1) % PFDdu.Length];
          }
       }
   }
}




任何人都可以帮助我解决这个问题.

问候,
Pawan.




Can any body help me on this plz..

with Regards,
Pawan.

推荐答案

有帮助吗?
C#中的组合算法 [使用C#泛型的排列,组合和变体 [
Does this help?
Combinatorial algorithms in C#[^]

What about this one?
Permutations, Combinations, and Variations using C# Generics[^]

Search on google, I am sure you will find.


这篇关于如何对组合进行计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆