设为首页 加入收藏

TOP

2011年计算机等级考试二级C语言辅导实例编程(6)
2014-10-29 19:30:08 来源: 作者: 【 】 浏览:77
Tags:2011年 计算机 等级考试 二级 语言 辅导 实例 编程

  动态规划求0/1背包问题


  #include


  #include


  #include


  //goods是一个或多个物品的重量和价值


  typedef struct goods


  {


  int weight;


  int value;


  } goods;


  //用来定义一个queryList数组


  //数组中的每个元素定义一趟需要记录的数据


  typedef struct queryList


  {


  goods *subResult; //一趟需要记录的数据


  int end; //指示该趟数据的最后一个元素


  } queryList;


  queryList* dknap(goods *Goods, int count, int capacity)


  {


  int i, j, next, pre, index, k;


  queryList *ql;


  goods cur;


  ql = (queryList *)malloc(sizeof(queryList)*count);


  ql[0].subResult = (goods*)malloc(sizeof(goods));


  ql[0].end = 0;


  编辑特别推荐:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2011年计算机等级考试二级C语言辅.. 下一篇2011年计算机等级考试二级C语言辅..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: