
-----------------------------------
eViruS
Mon Feb 28, 2011 1:51 pm

ANSI C backtracking Need Help
-----------------------------------
Hi guys , I have a problem to write maybe simple program. 
 I got number N  and number D and two guys.  N is number of thinks , D is number of worth of this things. 

Program must give theese two guys that same amount of worth that things.

For exaple we give number N = 7 so we got 7 numbers which are worth or N's):
 INPUT 
6
13
8
5
4
3
1
          Now if amount of all this numbers are divisible by 2 program goes foward (if not it printf "NO")  
program sort this numbers for TWO guys in such a way that they has that same amount of N numbers 

Somethink like that "

OUTPUT

First guy : 13 4
Sec guy  : 8 5 3 1

In INPUT it must printf numbers form the biggest to the smallest as u see. 

I stoped on this and i dont have any idea how to do this right.







#include
int reku(int result, int tab

-----------------------------------
DemonWasp
Mon Feb 28, 2011 3:53 pm

RE:ANSI C backtracking Need Help
-----------------------------------
Note: this problem is often impossible for a given input. For example, consider the input:
Given some number, N, of objects, with values D(0) to D(n-1) and sum of values S, find a set of objects that has value exactly S / 2.

Once you have one set with value exactly S / 2, the other set is obvious: just use all the other elements. This will also tell you very quickly whether the problem is possible: if no such set exists, the problem has no solution.  

The simplest way I can think of to implement this is to test all possible combinations of elements. You could make your program run slightly faster in some cases by noting that if D(i) > S  / 2 for any i, then the problem has no solution.

-----------------------------------
OneOffDriveByPoster
Wed Mar 02, 2011 6:27 pm

Re: ANSI C backtracking Need Help
-----------------------------------
Now if amount of all this numbers are divisible by 2 program goes foward (if not it printf "NO")Is this part of the problem statement? I am not sure that the description actually says that all the items must be assigned to one or the other. Perhaps we should try to minimize the number of unassigned objects with the constraint that the value assigned to each person is equal.

-----------------------------------
eViruS
Thu Mar 03, 2011 5:15 am

Re: ANSI C backtracking Need Help
-----------------------------------
i change code , but i need recursion which will be working like backtracking and search all possibilities to make output but i dont have any idea how to write it 
 
[code]
#include

int recursion()    
{
	
		
}



int main(int tab[], int tab1[],int bufor[])
{
int n, i;
scanf("%i" ,&n);  // Number of thinks


}
for(i=0; i