Cod sursa(job #1311877)

Utilizator Vele_GeorgeVele George Vele_George Data 8 ianuarie 2015 18:07:08
Problema Problema rucsacului Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>
#include <fstream>
#define nmax 10005
#define inf (1<<30)
using namespace std;

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

int main()
{

    int n,g,a[nmax], b[nmax],w,p;
    int *first, *second,*aux;

    first=a;
    second=b;

    f>>n>>g;


    for(int i=0; i<=g; i++)
    {
        *(first+i)= 0;
    }


    for(int i=1; i<=n; i++)
    {
        f>>w>>p;
        for(int j=1; j<w; j++) {*(second+j)=*(first+j); cerr<<*(second+j)<<" ";}
        for(int j=w; j<=g; j++){ *(second+j)=max(*(first+j-w)+p, *(first+j)); cerr<<*(second+j)<<" ";}
        cerr <<endl;
        aux=first;
        first=second;
        second=aux;
    }

    g<< *(first+g);


    return 0;
}