Cod sursa(job #902429)

Utilizator nosurrender99Bura Bogdan nosurrender99 Data 1 martie 2013 14:11:54
Problema Problema rucsacului Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 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,s=0;
    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];
            if( mat[i][j]>s)
                s=mat[i][j];
        }
    }
   /* for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=g;j++)
            fo<<mat[i][j]<<" ";
       fo<<endl;
    }*/
    fo<<s;
    return 0;
}