Topic Link: http://poj.org/problem?id=3628
Dynamic planning second question, or pure 01 backpack
To give N and b, and then give n number, with this n number of some, to find a and, this and is the minimum value of >=b, the output of the minimum and B difference.
Analysis: Here n items, weight of each item for C[i], value for w[i] and C[i]==w[i],, capacity for all C[i] and sum. Just start from scratch in f[] and find a minimal >=b is the solution to the problem
2014.4.10
///poj3628
#include <iostream>
#include <cstdio>
#include <cstring >
using namespace std;
int n,b;
int h[30];
int f[2000000];
int main ()
{
//Freopen ("in", "R", stdin);
Freopen ("Out", "w", stdout);
while (cin>>n>>b) {
int sum = 0;
for (int i=1; I<=n i++) {
cin>>h[i];
Sum + + h[i];
}
memset (F,0,sizeof (f));
for (int i=1; i<=n; i++) {for
(int j=sum; j>=1; j--) {
int A;
if (j-h[i]>=0)
a = F[j-h[i]]+h[i];
else
a = 0;
F[J] = f[j]>a? F[j]:a
}
}
for (int i = sum;; i--) {
if (f[i]<b) {
cout<<f[i+1]-b<<endl;
break;
}
}} return 0;
}