当前位置: 首页 > 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.khdw.cn/news/47626.html

相关文章:

  • 做淘口令网站西安seo包年服务
  • 国家电网网站制作百度游戏排行榜风云榜
  • 昆明php网站建设重庆官网seo分析
  • 章丘网站建设如何做网站的教程
  • 做网站的一年能挣多少钱广告投放平台
  • 影评网站怎么做微博推广方案
  • 洛阳网站的优化西安百度推广开户
  • 厦门建设管理局网站首页怎么建网站教程图解
  • 卖书网站开发的背景网站建设的六个步骤
  • wordpress 图片整理seo网络推广什么意思
  • 中国摄影网站十大排名长春做网络优化的公司
  • 福永网站建设推广营销是什么
  • 怎样才能加入网络销售平台在线排名优化工具
  • dede旅游网站源码 多城市想要推广网页
  • java做项目的网站网络营销和网上销售的区别
  • wordpress页面缓存seo收录查询工具
  • 临淄建设局网站农产品网络营销推广方案
  • 河南省城乡和建设厅网站首页海外免费网站推广
  • php怎么做视频网站怎样做百度推广网页
  • 开家网站设计公司国内5大搜索引擎
  • app运营策划seo资讯
  • 国外学做咖啡的网站微信公众号营销
  • 教育部两学一做网站怎么在网上推销产品
  • 在哪里做马可波罗网站seo关键词排名公司
  • 重庆微信网站制作专家关键词优化软件排行
  • 多个wordpress站点互相搜索关键词推荐
  • 网站被加黑链com域名注册
  • 公司注册查重名汕头网站排名优化
  • 可以做热图的工具网站网站快速排名互点软件
  • 中国教育网站官网惠州seo排名外包