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

网站经营伪静态nginx wordpress

网站经营,伪静态nginx wordpress,wordpress 前台注册登录,怎么在word添加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://www.zqtcl.cn/news/476328/

相关文章:

  • 手机网站模板用什么做高端展馆展厅设计方案
  • 长春企业网站seo国土网站建设自查报告
  • 建设电动车官方网站设立深圳公司
  • 蓝奏云注册网站工程设计方案主要内容
  • 建设官方网站企业网站公司可以做网站
  • 网站销售流程中装建设集团官网
  • 动易网站无法安装网站开发广告
  • 做网站类型注册域名com和cn
  • 织梦 做网站 知乎系统优化软件推荐
  • 长沙网站制作哪家强网站后台是怎么做的
  • Linux网站开发设计做ppt网站动态
  • 西部中大建设集团网站微商代理网
  • 做网站的参考文献有哪些火车头采集 wordpress
  • 网站不备案会有什么影响最新企业名录搜索软件
  • 邯郸做网站公司哪家好优化设计四年级下册数学答案
  • wordpress企业建站模版wordpress门户网站模板
  • 网站建设时间及简介企业注册代理
  • 网站首页制作方案wordpress中常用插件安装包
  • 阿里云建立网站赤坎网站建设公司
  • 时光轴 网站小公司做网站赚钱吗
  • 手机管理网站模板乐山住房和城乡建设厅网站
  • wordpress链接样式设置方法网络seo推广培训
  • 建站系统wordpress下载企业网站建设课程体会
  • 网站资源规划怎么写wordpress怎么解绑域名
  • 建湖企业做网站多少钱网页开发工具软件
  • WordPress怎么建小站wordpress替换谷歌字体库
  • ps建设网站步骤佛山做外贸网站特色
  • 杭州做代发的网站有哪些计算机基础网站建设和网络安全
  • 做汽配外贸是在哪个网站做山东百度推广
  • 网站类型大全cms监控软件下载官网