Cod sursa(job #2031828)

Utilizator ApolodorTudor Fernea Apolodor Data 3 octombrie 2017 21:19:56
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>

using namespace std;

int n,cost,i,j;
int a[1001],b[1001],d[1001][1001];

ifstream fi("energii.in");
ofstream fo("energii.out");

int main()
{
   fi>>n;
   fi>>cost;
   for(i=1;i<=n;i++)
    fi>>a[i]>>b[i];
   for(i=0;i<=n;i++)
    for(j=0;j<=cost;j++)
    d[i][j]=300000000;
    d[0][0]=0;
   for(i=1;i<=n;i++)
    for(j=0;j<=cost;j++)
    d[i][j]=min(d[i-1][j],d[i][j-a[i]]+b[i]);
   fo<<d[n][cost];
}