Pagini recente » Cod sursa (job #1720980) | Cod sursa (job #1054708) | Cod sursa (job #2581025) | Cod sursa (job #1628200) | Cod sursa (job #3134079)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5000
int n , g , maxim=0;
typedef struct obiect
{
int greutate;
int profit;
}obiect;
obiect array[SIZE];
void backtracking(int p_curent , int g_curent , int poz)
{
if(p_curent>maxim)
{
maxim=p_curent;
}
for(int i=poz ; i<n ; i++)
{
if(array[i].greutate+g_curent<=g)
{
backtracking(array[i].profit+p_curent , array[i].greutate+g_curent , i+1);
}
}
}
int main(void)
{
FILE *f=fopen("rucsac.in" , "r") , *g=fopen("rucsac.out" , "w");
fscanf("%d %d" , &n , &g);
for(int i=0 ; i<n ; i++)
{
fscanf("%d %d" , &array[i].greutate , &array[i].profit);
}
backtracking(0 , 0 , 0);
fprintf("%d\n" , maxim);
return 0;
}