作业帮 > 综合 > 作业

c语言0-1背包问题高手进来

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/14 13:10:17
c语言0-1背包问题高手进来
给定n种物品和1个背包,物品i的重量是wi,其价值为vi,背包的容量为C.要求选择装入背包的物品,使得装入背包中物品的总价值最大.
Input
每组测试数据包含3行,第1行为n和c,表示有n(0
#include "stdio.h"
#include "time.h"
#define BOXMAX 10
typedef struct BOX
{
int locate[BOXMAX];
float weight[BOXMAX];
float price[BOXMAX];
int n;
}box;
void main()
{
box bx;
int sign=0;
int row,line;
int maxbox;
int tmp;
float maxvalue=0;
int b_n;
float input;
float b_total;
float gotcount=0;
srand(time(NULL));
while(!sign)
{
printf("input the number of bpx:");
scanf("%d",&b_n);
printf("\nintput the weight of box:");
scanf("%f",&b_total);
if(b_n