最佳方案,大量置换NPR [英] Best program for Permutation nPr of large numbers
问题描述
我是新来编程,并停留在置换一部分。我有code的工作对存储在矩阵大数的组合,但我无法找到我应该怎么在改变得到的结果。 我试过排列递归方法,但不能达到立竿见影的效果。
这是我得到的组合code应该是什么状况的改变,我应该做在这里得到排列?
无效的组合()
{
INT I,J;
对于(i = 0; I< 100;我++)
{
nCr的[I] [0] = 1;
nCr的[I] [I] = 1;
}
对于(i = 1; I< 100;我++)
为(J = 1; J< 100; J ++)
如果(我!= j)条
{
nCr的[I] [j]的=(NCR [I-1] [j]的+ nCr的[I-1] [J-1]);
}
}
有关排列的重复规则可以自定义很容易得出:
NPK = N *(N-1)*(N-2)* ... *(N-K + 1)= N *(N-1)p(K -1)
转换为code:
为(i = 0; I< 100;我++)
{
NPR [I] [0] = 1;
}
对于(i = 1; I< 100;我++)
为(J = 1; J< 100; J ++)
如果(我!= j)条
{
NPR [I] [j]的= I * NPR [I-1] [J-1];
}
需要注意的是排列的数量增长快,溢出的可用存储空间 INT
:13P11比如已经超出了范围有符号32位整数。
I am new to programming and was stuck at the permutation part. I have code which works for combination of large numbers which is stored in matrix but i am not able to find what should i change in that to get the result. I tried the recursive method for permutations but could not achieve fast results.
This is the code which i got for combination what should be the change in condition which i should do here to get permutations?
void combination()
{
int i,j;
for(i=0;i<100;i++)
{
nCr[i][0]=1;
nCr[i][i]=1;
}
for(i=1;i<100;i++)
for(j=1;j<100;j++)
if (i!=j)
{
nCr[i][j] = (nCr[i-1][j] + nCr[i-1][j-1]);
}
}
A recurrence rule for permutations can be easily derived from the definition:
nPk = n*(n-1)*(n-2)* ... * (n-k+1) = n * (n-1)P(k-1)
Converted to code:
for(i=0;i<100;i++)
{
nPr[i][0]=1;
}
for(i=1;i<100;i++)
for(j=1;j<100;j++)
if (i!=j)
{
nPr[i][j] = i * nPr[i-1][j-1];
}
Note that the number of permutations grows fast and overflows the storage available for int
: 13P11 for example is already out of range with signed 32bit integers.
这篇关于最佳方案,大量置换NPR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!