Cod sursa(job #875765)

Utilizator vandrei95Zamfir Vlad vandrei95 Data 10 februarie 2013 19:24:05
Problema Energii Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include<fstream>
#define INF 9999999
using namespace std;
int P[1003],E[1003],d[1003][5003];
int main()
{
    fstream f("energii.in",ios::in),g("energii.out",ios::out);
    int G,W,i,j;
    f>>G>>W;
    for(i=1;i<=G;i++)
        f>>E[i]>>P[i];
    for(i=0;i<=G;i++)
        for(j=0;j<=W;j++)
            d[i][j]=INF;
    for(i=1;i<=G;i++)
        for(j=1;j<=W;j++)
        {
            if(E[i]<j)
                d[i][j]=min(d[i-1][j],d[i-1][j-E[i]]+P[i]);
            else
                d[i][j]=min(d[i-1][j],P[i]);
        }
    g<<d[G][W];



}