当前位置: 首页 > 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.hengruixuexiao.com/news/10441.html

相关文章:

  • 网站怎么建在国外网站推广的全过程
  • 用php做美食网站百度网址大全手机版
  • 厦门网站建设是什么意思淘宝搜索关键词查询工具
  • 企业网站建设一条线上营销活动案例
  • 网站上怎么做企业推广百度知道合伙人
  • 大学生做外包项目的网站深圳网络推广哪家比较好
  • 怎么用电脑自带软件做网站页面瑞金网络推广
  • 网站建设费计入 科目磁力猫torrentkitty官网
  • 网站建设会计分录怎么写武汉网站建设方案优化
  • 单页面网站制作技术百度上做推广怎么收费
  • 我想学网站建设百度关键词挖掘工具爱站网
  • 动易做网站广西南宁做网站的公司
  • 央美老师做的家具网站百度网站如何优化排名
  • 网站后端技术语言建站模板网站
  • 微信如何自己开发小程序seo技术培训岳阳
  • 自己怎么做商城网站视频教程免费关键词优化排名软件
  • 做那个的网站谁有英文谷歌优化
  • 电商加盟网站建设成都关键词优化报价
  • 广州建筑东莞分公司北京网站优化校学费
  • http:www.qdgw.edu.cn 网站建设综合实训超级推荐的关键词怎么优化
  • 网站开发ceil(5.5)百度信息流效果怎么样
  • 网站建设空间什么意思网络推广哪家做得比较好
  • 做字幕模板下载网站seo网络推广经理招聘
  • wordpress 字体设置seo短视频网页入口引流免费
  • 我想克隆个网站 怎么做怎样做网络推广挣钱
  • 自建网站多少钱网游百度搜索风云榜
  • 网站域名到期后果产品推广计划方案
  • 大悟网站设计网络营销策略制定
  • wordpress怎么设置网站描述长沙网站建站模板
  • 南通企业做网站网推接单平台有哪些