Cod sursa(job #1346436)

Utilizator superman_01Avramescu Cristian superman_01 Data 18 februarie 2015 11:42:50
Problema Problema rucsacului Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>

#define NMAX 100005
#define get_max(a,b) ((a)>(b)?(a):(b))
#define get_min(a,b) ((a)<(b)?(a):(b))

using namespace std;

ifstream in ( "rucsac.in" ) ;
ofstream out ( "rucsac.out" );

int N , G;
int weight , profit;
int DP[NMAX];

int main ( void ){
   int i , j ;
   in >> N >> G ;
   for ( i = 1 ; i <= N ; ++i ){
     in >> weight >> profit ;
     for ( j = G ; j >= weight ; --j )
      DP[j] = get_max(DP[j] , DP[j-weight] + profit);
   }
   out << DP[G];
   return  0 ;
}