Cod sursa(job #1042665)

Utilizator tudor0013tudor petrescu tudor0013 Data 27 noiembrie 2013 16:03:14
Problema Problema rucsacului Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <cstdio>
using namespace std;

int v1[10001],v2[10001],n,g;

int main()
{
    int i,j,x,y;
    freopen("rucsac.in","r",stdin);
    freopen("rucsac.out","w",stdout);
    scanf("%d%d",&n,&g);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        for(j=x;j<=g;j++)
        {
            v2[j]=v1[j-x]+y;
            if(v2[j]<v1[j])
                v2[j]=v1[j];
        }
        for(j=1;j<=g;j++)
            v1[j]=v2[j];
    }
    printf("%d",v1[g]);
    return 0;
}