Cod sursa(job #3283314)

Utilizator Martin_BohonyiMartin Bohonyi Martin_Bohonyi Data 8 martie 2025 23:43:58
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include<iostream>
using namespace std;

/*
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
*/

long long N , GMaxx , DP[10001];

struct Obiect{
     int G;
     int V;
 }O[1001];

int main()
{
cin>>N>>GMaxx;
for(int i=1 ; i<=N ; i++)
    cin>>O[i].G>>O[i].V;

for(int i=1 ; i<=N ; i++){
   for(int cw=GMaxx ; cw>=1 ; cw--){
        if(cw >= O[i].G)
            DP[cw]=max(DP[cw] , O[i].V + DP[cw-O[i].G]);
        else
            DP[cw]=DP[cw];

   }

 }

cout<<DP[GMaxx]<<'\n';
return 0;
}