Hello

I want to program for ship game : according to below text

For example we have 4 ship and we have a table 4*4 and we want put ship in this table according to capacity of column and row.

Therefore I used backtracking and for this shape is true answer .

http://upload.ugm.ac.id/434shape.docx
It is true answer when we have ships enter with this order : ship 1-ship2- ship3-ship4

But if ships had this order : ship 2-ship1- ship3-ship4 the answer will be wrong.

Actually if input shape was according to below shape , my answer is wrong.

http://upload.ugm.ac.id/434shape.docx[

^]

Can any body help me?

My code is :

void General::Ship(int count,int k,int n) {
int lenght;
lenght=L[count];
for (int x=1;x<=n;x++)
{
for(int y=1;y<=n;y++)
{
if (IsOkhorizontal(x,y,lenght,n)==1 )
{
Horizontally(x,y,lenght,count,n);
if(count==k)
{
Print();
}
else
Ship(count+1,k,n);
}
if (IsOkvertical(x,y,lenght,n)==1)
{
Vertically(x,y,lenght,count,n);
if(count==k)
{
Print();
}
else
Ship(count+1,k,n);
}
}
}
}

For this example we should calling ship(1,4,4)

thanks