c语言代码:装箱问题
#include <stdlib.h>
int v,n,i,j,k,a[5]={0,2,3,4,5,6}
};
int f[1000];
int findMinRemain(int v,int n){
f[0] = 1;
for (i = 1; i <= n; i ++ ){
for (j = v; j >= a[i]; j -- ){
if (!f[j] && f[j - a[i]]) f[j] = 1;
}
}
for ( k = v; k > 1 && !f[k]; k -- );
printf("%d\n", v - k);
return v-k;
}
c语言代码:背包问题
#include <stdlib.h>
int v,n,i,j,k,a[5]={0,2,3,4,5};
int value[5] = {0, 3, 4, 5,6};
int f[1000];
int package(int v,int n){
f[0] = 0;
for (i = 1; i <= n; i ++ ){
for (j = v; j >= a[i]; j -- ){
if (f[j - a[i]] + value[i] > f[j])
f[j] = f[j - a[i]] + value[i];
}
}
return f[v];
}