Cod sursa(job #677152)
| Utilizator | Data | 9 februarie 2012 21:30:20 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | sim_2 | Marime | 0.52 kb |
#include<fstream>
using namespace std;
#define gmax 10003
#define nmax 5003
int x[2][gmax],greut[nmax],profit[nmax],n,G;
int mare(int a, int b)
{
if(a>b) return a;
return b;
}
int main()
{
ifstream f("rucsac.in");
ofstream g("rucsac.out");
f>>n>>G;
for(int i=1;i<=n;i++)
f>>greut[i]>>profit[i];
int l=0;
for(int i=1;i<=n;i++,l=1-l)
for(int j=0;j<=G;j++)
{
x[1-l][j]=x[l][j];
if(greut[i]<=j)
x[1-l][j]=mare(x[1-l][j],x[l][j-greut[i]]+profit[i]);
}
g<<x[l][G];
}
