Here is the problem statement.
This is another classic problem of dynamic programming called Knapsack problem with 2 parameters. Read about knapsack probelm with 2 parameters here.
This is another classic problem of dynamic programming called Knapsack problem with 2 parameters. Read about knapsack probelm with 2 parameters here.
Hi David! I love this blog. It's really helpful. I am currently running inot a problem while submitting the solution to this problem on spoj. I downloaded your source code and ran it for a few tezt cases and found that the answers were similar to that of mine. Here is my source code. Please help.
ReplyDelete#include
using namespace std;
struct coin
{
float v,w,r;
};
void mergesort(coin a[],int start,int end)
{
int i=start,j=(start+end)/2+1;
if(start>t;
while(t--)
{
cin>>e>>f;
cin>>n;
coin c[n];
for(i=0;i>c[i].v>>c[i].w;
c[i].r=c[i].v/c[i].w;
}
mergesort(c,0,n-1);
int total=0,index=0,value=0;
while(true)
{
if(c[index].w<=f-e-total)
{
int mult=(int)(f-e-total)/c[index].w;
value+=c[index].v*mult;
total+=c[index++].w*mult;
if(total==f-e)
{
cout<<"The minimum amount of money in the piggy-bank is "<>t;
}
Thanks in advance.
Hi. For making it easier for me to check and for us to keep in contact please send your cpp file to email helpinprogramming@gmail.com
DeleteI have emailed you the cpp file. Please check it. Thanks in advance.
DeleteSorry.The code wasn't posted completely in the previous comment.
ReplyDeletebreak;
}
}
else
{
cout<<"This is impossible.\n";
break;
}
}
}
// cin>>t;
}