# MAC skills: how to repairs the copy and paste that cannot be repaired

2022-12-30   ES

Typical complete backpack problem, but this question is not a simple complete backpack, a little deformation. The previous complete backpack was the maximum value of the items that could be put in the same space. But this time is the minimum value. Need to transform your mind. At the beginning, the teammates said that this was a simple complete backpack, and the water passed. I think it takes for granted that it is only the last value, and the result is various WAs. Later I discovered my mistake. Alas, teammates are deliberately pitted …

Question ideas: Just talk about where the transformation is needed. In the past, we all initialized the array into an infinite value. Now we need to define the array as infinitely large. We need to constantly update to find the minimum value.

code is as follows:

``````#include<stdio.h>
#include<string.h>
int a,b,v;
int main()
{  //freopen("I:\\Input.txt","r",stdin);
int i,j,k,l,n,m,w,w1,w2;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&w1,&w2);
w=w2-w1;
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d%d",&a[i],&b[i]);
for(i=1;i<=w;i++)
v[i]=999999999;
v=0;
for(i=0;i<m;i++)
for(j=b[i];j<=w;j++)
{
if(v[j]>v[j-b[i]]+a[i])
v[j]=v[j-b[i]]+a[i];
}
if(v[w]==999999999)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",v[w]);
}
return 0;
}``````

Facts once again proved to me again that I am just a rookie who cannot dish. In the future, I can only learn new things according to my own beats.

source