当前位置: 首页 > news >正文

小网站建设公司做网站时字幕怎么做

小网站建设公司,做网站时字幕怎么做,建立平台型组织第一步需要做什么,wordpress归档页面实验五 分支限界法 01背包问题的分治限界法的实现 剪枝函数 限界函数 1.实验目的 1、理解分支限界法的剪枝搜索策略#xff0c;掌握分支限界法的算法框架 2、设计并实现问题#xff0c;掌握分支限界算法。 2.实验环境 java 3.问题描述 给定n种物品和一背包。物品i的重…实验五  分支限界法 01背包问题的分治限界法的实现 剪枝函数 限界函数 1.实验目的 1、理解分支限界法的剪枝搜索策略掌握分支限界法的算法框架 2、设计并实现问题掌握分支限界算法。 2.实验环境 java 3.问题描述 给定n种物品和一背包。物品i的重量是wi其价值为vi背包的容量为C。问应如何选择装入背包的物品使得装入背包中物品的总价值最大? 4.复杂度 算法整体的时间复杂度主要由回溯操作的时间复杂度决定在最坏情况下为O(2^n)。然而在实际应用中由于剪枝操作的存在实际的分支数会远远小于2^n因此算法的执行时间通常会有所缩减。 5.算法实现 package shiyan5;import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner;class Item {int weight;int value;double density; // 物品的单位价值价值重量比public Item(int weight, int value) {this.weight weight;this.value value;this.density (double) value / weight;} }public class BranchAndBound {static ListItem items;static int capacity;static int maxTotalValue;static ListItem selectedItems;public static void main(String[] args) {readInputData(input.txt);branchAndBound();writeOutputData(output.txt);}private static void readInputData(String filename) {try {File file new File(filename);Scanner scanner new Scanner(file);int n scanner.nextInt();capacity scanner.nextInt();items new ArrayList();for (int i 0; i n; i) {int weight scanner.nextInt();int value scanner.nextInt();items.add(new Item(weight, value));}scanner.close();} catch (IOException e) {e.printStackTrace();}}private static void branchAndBound() {Collections.sort(items, (a, b) - Double.compare(b.density, a.density)); // 按单位价值从大到小排序maxTotalValue 0;selectedItems new ArrayList();backtrack(0, 0, 0);// 按照物品的原始顺序排序Collections.sort(selectedItems, (a, b) - Integer.compare(items.indexOf(a), items.indexOf(b)));}private static void backtrack(int level, int currentWeight, int currentValue) {if (level items.size() || currentWeight capacity) {if (currentValue maxTotalValue) {maxTotalValue currentValue;selectedItems.clear();for (int i 0; i level; i) {if (items.indexOf(items.get(i)) ! -1) {selectedItems.add(items.get(i));}}}return;}if (currentWeight items.get(level).weight capacity) {currentWeight items.get(level).weight;currentValue items.get(level).value;backtrack(level 1, currentWeight, currentValue);currentWeight - items.get(level).weight;currentValue - items.get(level).value;}if (bound(level 1, currentWeight, currentValue) maxTotalValue) {backtrack(level 1, currentWeight, currentValue);}}private static double bound(int level, int currentWeight, int currentValue) {double maxBound currentValue;int currentLevel level;int currentWeightSum currentWeight;while (currentWeightSum capacity currentLevel items.size()) {if (currentWeightSum items.get(currentLevel).weight capacity) {currentWeightSum items.get(currentLevel).weight;maxBound items.get(currentLevel).value;} else {double remainingWeight capacity - currentWeightSum;maxBound (remainingWeight / items.get(currentLevel).weight) * items.get(currentLevel).value;break;}currentLevel;}return maxBound;}private static void writeOutputData(String filename) {try {FileWriter writer new FileWriter(filename);writer.write(背包中物品的总价值: maxTotalValue);writer.write(\n\n已选物品列表:\n);for (Item item : selectedItems) {writer.write(重量: item.weight , 价值: item.value);writer.write(\n);}writer.close();System.out.println(输出成功);} catch (IOException e) {e.printStackTrace();}} }输入 运行 输出
http://wiki.neutronadmin.com/news/300495/

相关文章:

  • 银行网站源码网页与网站设计什么是主题
  • 中山精品网站建设资讯做网站的教科书
  • 一流的微商城网站建设网站开发及设计演讲海报
  • 做视频官方网站京东商城网站建设目标
  • 免费电商网站建设网站更换备案
  • t恤图案设计网站常州免费做网站
  • dede的网站地图要怎么做网站空间格式asp
  • 南京医院手机网站建设邢台做网站优化费用
  • 金融集团网站模板怎样制作网站积分系统
  • 高端网站建设制作设计夫唯seo培训
  • 南京做网站团队想搞网站建设
  • wordpress备份网站淘宝网站图片维护怎么做
  • 做网站中网页的大小网站建设用户需求
  • 个人成立公司怎么做企业网站建设网站和备案
  • 网站建设企业有哪些哪里可以做网站啊
  • 深圳专业网站建设技术微信商城怎么弄
  • 网站开发的分工网站子目录是什么
  • 提供网站制作公司哪家专业做网站需要注意的地方
  • 商城网站开发技术可行性分析单页营销型网站建设
  • 济源网站建设费用wordpress怎么适应手机
  • 外贸网站建设推广公司前景如何网站设计制作培训
  • 网站开发如何dw中小手wordpress的ping
  • 淄博周村网站建设报价如何让新网站
  • 单页网站多钱淄博网站建设0533cl
  • dedecms中餐网站模板旅游网站怎样做宣传
  • 医学网站建设方案找公司做网站多少钱成都
  • 电商类网站怎么做推广海南百度推广运营中心
  • 有什么网站做微商重庆建设工程信息网30系统
  • 网站开发流程可规划为哪三个阶段php技术应用于中小企业网站开发
  • 关方网站买微信destoon做的网站