Pagini recente » Cod sursa (job #175432) | Cod sursa (job #80847) | Cod sursa (job #934974) | Cod sursa (job #2060681) | Cod sursa (job #767300)
Cod sursa(job #767300)
#include<fstream>
using namespace std;
int n,S,sol[5002],Gmax=5002,i,j,G,C;
int main()//7/13/2012; 10:40 trebuie sa obtin o greutate cu cost total minim
{
ifstream f("energii.in");ofstream g("energii.out");
f>>n>>S;
for(i=1;i<=S;i++)sol[i]=-1;
for(i=1;i<=n;i++)
{
f>>G>>C;
for(j=0;j<=S;j++)
if(sol[j-G]!=-1)
{
if(j-G>=0)
{
if( sol[j]==-1 || C+sol[j-G] < sol[j] )
sol[j]=C+sol[j-G];
}
//else if(sol[S]==-1||C+sol[j]<sol[S])
// sol[S]=C+sol[j];
}
}
g<<sol[S]<<'\n';
f.close();g.close();
return 0;}