Cod sursa(job #901102)

Utilizator nosurrender99Bura Bogdan nosurrender99 Data 1 martie 2013 00:19:56
Problema Problema rucsacului Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>
#include <iostream>
using namespace std;

fstream f("rucsac.in" , ios::in), fo("rucsac.out", ios::out);

int mat[5001][10001];

int main()
{
    int n,g,v,w;
    f>>n>>g;
    for(int i=1;i<=n;i++)
    {
        f>>w>>v;
        for(int j=w;j<=g;j++)
        {
            if(mat[i-1][j-w]+v>mat[i-1][j])
                mat[i][j]=mat[i-1][j-w]+v;
            else
                mat[i][j]=mat[i-1][j];
        }
    }
   /* for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=g;j++)
            fo<<mat[i][j]<<" ";
       fo<<endl;
    }*/
    fo<<mat[n][g];
    return 0;
}