Cod sursa(job #2779001)
| Utilizator | Data | 2 octombrie 2021 14:56:51 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <iostream>
#include <vector>
using namespace std;
struct obiect
{
int greutate;
int profit;
};
vector <obiect> v;
int dp[10009];
int main()
{
int n;
cin>>n;
int gmax;
cin>>gmax;
for(int i=0;i<n;i++)
{
int g,p;
cin>>g>>p;
obiect nou;
nou.greutate=g;
nou.profit=p;
v.push_back(nou);
}
for(int j=0;j<n;j++)
{
for(int g=gmax;g>=0;g--)
{
if(g-v[j].greutate>=0)
dp[g]=max(dp[g],dp[g-v[j].greutate]+v[j].profit);
}
}
cout<<dp[gmax];
return 0;
}
