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

创建自己的博客网站吗做企业网站比较好的公司

创建自己的博客网站吗,做企业网站比较好的公司,营销宣传图片,淘宝官网首页版本有依赖的背包是指多个物品变成一个复合物品(互斥),每件复合物品不要和怎么要多种可能性展开。时间复杂度O(物品个数 * 背包容量),额外空间复杂度O(背包容量)。 下面通过题目加深理解。 题目一 测试链接:[NOIP2006 提…

有依赖的背包是指多个物品变成一个复合物品(互斥),每件复合物品不要和怎么要多种可能性展开。时间复杂度O(物品个数 * 背包容量),额外空间复杂度O(背包容量)。

下面通过题目加深理解。

题目一

测试链接:[NOIP2006 提高组] 金明的预算方案 - 洛谷

分析:对于这道题,可以参考01背包是对每个物品进行可能性的展开,有依赖的背包是对主件进行可能性的展开,所以可能性就比01背包的展开多。对于一个没有附件的主件可能性的展开,就是01背包的展开,即选或不选主件。对于有一个附件的主件可能性的展开,就有三种,选主件、不选主件、主件和附件一起选。对于有两个附件的主件可能性的展开,就有五种,选主件、不选主件、主件和第一个附件一起选、主件和第二个附件一起选、主件和两个附件一起选。对于输入,代码中采用了几个数组结构存储信息,cost数组存储花费代价,value数组存储收益,king数组存储是否是主件,fans数组存储主件有多少个附件,follows数组存储每个主件拥有的附件。下面代码采用计划搜索,并没有去做空间压缩,代码如下。

#include <iostream>
#include <vector>
using namespace std;
int n, m;
int cost[61];
int value[61];
bool king[61];
int fans[61] = {0};
vector<vector<int>> follows;
int dp[61][32001];
int f(int index, int money){if(index == m+1){return 0;}if(dp[index][money] != -1){return dp[index][money];}if(!king[index]){return f(index+1, money);}int ans = f(index+1, money);if(money - cost[index] >= 0){ans = ans > f(index+1, money-cost[index]) + value[index] ?ans : f(index+1, money-cost[index]) + value[index];}if(fans[index] >= 1 && money - cost[index] - cost[follows[index][0]] >= 0){ans = ans > f(index+1, money-cost[index]-cost[follows[index][0]]) + value[index] + value[follows[index][0]] ?ans : f(index+1, money-cost[index]-cost[follows[index][0]]) + value[index] + value[follows[index][0]];}if(fans[index] == 2){if(money - cost[index] - cost[follows[index][1]] >= 0){ans = ans > f(index+1, money-cost[index]-cost[follows[index][1]]) + value[index] + value[follows[index][1]] ?ans : f(index+1, money-cost[index]-cost[follows[index][1]]) + value[index] + value[follows[index][1]];}if(money - cost[index] - cost[follows[index][0]] - cost[follows[index][1]] >= 0){ans = ans > f(index+1, money-cost[index]-cost[follows[index][0]]-cost[follows[index][1]]) + value[index] + value[follows[index][0]] + value[follows[index][1]] ?ans : f(index+1, money-cost[index]-cost[follows[index][0]]-cost[follows[index][1]]) + value[index] + value[follows[index][0]] + value[follows[index][1]];}}dp[index][money] = ans;return ans;
}
int main(void){int v, p, q;scanf("%d%d", &n, &m);vector<int> temp;for(int i = 0;i <= m;++i){follows.push_back(temp);}for(int i = 1;i <= m;++i){scanf("%d%d%d", &v, &p, &q);cost[i] = v;value[i] = v * p;if(q != 0){king[i] = false;fans[q]++;follows[q].push_back(i);}else{king[i] = true;}}for(int i = 1;i < 61;++i){for(int j = 1;j < 32001;++j){dp[i][j] = -1;}}printf("%d", f(1, n));return 0;
}

http://www.yayakq.cn/news/779011/

相关文章:

  • 徐州网站制作机构全网商机app招标
  • jquery网站后台慈溪市规划建设网站
  • 佛山高端网站建设工作室如何做一个企业的网站
  • 网站建设 中企动力 顺德浙江中天建设集团有限公司网站
  • 设计视频网站做网站的步骤视频
  • 如何给网站做seo自己建网站需要什么
  • 零基础学网站建设 知乎互联网项目招商加盟
  • 上海网站优化海佛山手机建站模板
  • 无锡高端网站设计公司价格wordpress p=29
  • 高端网站设计v芯hyhyk1推好网站策划常用软件
  • 带有客户案例的网站wordpress中文文章排版插件
  • 网站建设专业学什么在哪里可以学装修设计
  • 网站推广工作内容行情软件app
  • linux搭建个人网站诚信通国际网站怎么做
  • 英文购物网站模板广州网站开发水平广州亦客网络
  • 广州从化网站建设昌邑建设局网站
  • 做网站的公司有哪些怎么拉人做推广
  • 湛江网站制作公司对电子政务网站建设的建议
  • wordpress网站迁移问题全屋定制需要的软件
  • 如何进行网站营销动画制作软件免费
  • 济南网站建设外包公司哪家好wordpress手机号网站
  • 龙华个人网站建设中建集团的重要事件
  • 网站前面的logo标志正在为您跳转中
  • 做网站的主题有哪些运营是做什么的工作
  • 做电影网站 资源怎么存放深圳网站设计收费
  • 北京汉邦未来网站建设有限公司适合手机的网站
  • 网站如何收费360建筑网挂行情
  • 企业网站的开发公司如何注册新公司
  • 网站流量下降原因咋样着做自己的网站
  • 福建泉州做网站公司哪家好苏州保洁公司多少钱一个平方