\binom nk = \frac{n(n-1)\ldots(n-k+1)}{k(k-1)\dots1},
which can be written using factorials as \frac{n!}{k!(n-k)!} whenever k\leq n, and which is zero when k > n. The set of all k-combinations of a set S is sometimes denoted by
\binom Sk\,.
Combinations can consider the combination of n things taken k at a time without or with repetitions.
*/
# include
using namespace std;
bool used[256]={0}; //Concept nCr
int r=3;
char a[] = "ABCD";
//int length=strlen(pIn);
void printOutPutArray(char *out,int outIndex){
for(int i=0;i
}
void combinations(char *out, int outIndex, int included,int length)
{
if (included==r) {printOutPutArray(out,outIndex); return;
}
for (int i=0;i
if (used[i]) continue;
out[outIndex++] = a[i];
used[i]=1;
combinations(out, outIndex, included+1,length);
used[i]=0;
outIndex--;
}
}
//st above functions */
int main()
{
char out[100];
combinations(out, 0, 0,4);
return 0;
}
No comments :
Post a Comment