Cod sursa(job #3313844)
| Utilizator | Data | 7 octombrie 2025 09:32:03 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <bits/stdc++.h>
using namespace std;
int n,k,rez=0;
struct sigma
{
int cost,greutate;
};
sigma v[5005];
void Rezolv(int a,int b,int c)
{
if(a==n+1)
{
if(c<=k)
rez=max(rez,b);
}
else
{
if(c+v[a].greutate<=k)
Rezolv(a+1,b+v[a].cost,c+v[a].greutate);
Rezolv(a+1,b,c);
}
}
int main()
{
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>v[i].greutate>>v[i].cost;
Rezolv(1,0,0);
cout<<rez;
return 0;
}
