Cod sursa(job #37980)
Utilizator | Data | 25 martie 2007 13:12:40 | |
---|---|---|---|
Problema | Distincte | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.34 kb |
#include<fstream.h>
int main()
{ifstream f("barbie.in");
ofstream h("barbie.out");
int pg,pp,n,v[1000],g[1000],a[1000],i,j;
f>>pg>>pp>>n;
for(i=1;i<=n;i++)
f>>v[i]>>g[i];
a[1]=0;
for(j=1;j<=pp;j++)
{
for(i=1;i<=n;i++)
if (g[i]<=j) if (a[j-g[i]]+v[i]<a[j]) a[j]=a[j-g[i]]+v[i];}
h<<a[pp];}