now I try correct this question ,suppose this condition
n=3 and p(head)=1/3
and in output we have
(1==H,0==T)
1 0 0
0 1 0
0 0 1
this program shows all the situations
(non-repeated permutations) could occur
Code:
//Check for different numbers
int check(int *a,int f,int k,int n)
{
for(int i=f;i<k;i++)
{
if (a[i]==a[k]) return 1;
}
return 0;
}
//Generate all the permutations of a[k]..a[n-1]
//a is an array and n is the lenght of the array
//k is the statrting index for generating permutations
void p(int *a,int k,int n)
{
if(k==n-1)
{
for(int i=0;i<n;i++)
{
Console::Write(a[i]);
}
Console::WriteLine();
}
else
{
for(int i=k;i<n;i++)
{
//if this value differs others generate permutations
if(!check(a,k,i,n))
{
int temp=a[k];a[k]=a[i];a[i]=temp;
p(a,k+1,n);
temp=a[k];a[k]=a[i];a[i]=temp;
}
}
}
}
int _tmain()
{
int a[4];
a[0]=1;//optional,two times H and two times T
a[1]=0;
a[2]=0;
a[3]=1;
p(a,0,4);
Console::Read();
return 0;
}
if you cant get somewhere tell me I will explain it more exact how I wrote it.
--------------------------------------------
Mehdi.:)