Cod sursa(job #1956828)

Utilizator thinkphpAdrian Statescu thinkphp Data 7 aprilie 2017 08:28:43
Problema Problema rucsacului Scor 65
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <bits/stdc++.h>
#define FIN "rucsac.in"
#define FOUT "rucsac.out"
#define MAXW 10001
#define MAXC 10001
#define MAXP 10001

using namespace std;


int main() {
  int i, j, n, g;
  int w[MAXW], c[MAXC], Cost[MAXP];

  ifstream fin(FIN);
  ofstream fout(FOUT);

  fin>>n>>g;

  for(i = 1; i <= n; i++) {
      fin>>w[i]>>c[i];
  }

  for(i = 0; i <= n; ++i) 

      for(j = g; j >= w[i]; j--) 

          Cost[ j ] = max(Cost[j], Cost[j - w[i]] + c[i]);



  fout<<Cost[g];


 return(0);
}