Pagini recente » Cod sursa (job #128373) | Cod sursa (job #593636) | Cod sursa (job #1205430) | Cod sursa (job #46839) | Cod sursa (job #2713254)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n,g;
int smax;
typedef struct obiect_t{
int val;
int greutate;
}obiect;
obiect obiecte[5000];
void recursiv(int k, int gc, int pc){
for(int i=0;i<=1;i++){
if(i==1){
int tgc=gc+obiecte[k].greutate;
int tpc=pc+obiecte[k].val;
if(tgc<=g){
if(tpc>smax)
smax=tpc;
if(tgc<g && k<n-1)
recursiv(k+1,tgc,tpc);
}
}else if(k<n-1)
recursiv(k+1,gc,pc);
}
}
int main()
{
fin>>n>>g;
for(int i=0;i<n;i++)
fin>>obiecte[i].greutate>>obiecte[i].val;
recursiv(0,0,0);
fout<<smax;
return 0;
}