科林明伦杯哈尔滨理工大学第七届程序设计团队赛-Aggie’s Tasks
来源:互联网 发布:最新淘宝店铺教程视频 编辑:程序博客网 时间:2024/05/01 08:44
Aggie is faced with a sequence of tasks, each of which with a difficulty value di and an expected profit pi. For each task, Aggie must decide whether or not to complete it. As Aggie doesn’t want to waste her time on easy tasks, once she takes a task with a difficulty di, she won’t take any task whose difficulty value is less than or equal to di.
Now Aggie needs to know the largest profits that she may gain.
InputThe first lineconsists of onepositive integer t (t≤ 10), which denotes the number of test cases.
For each test case, the first line consists one positive integer n (n≤ 100000), which denotes the number of tasks. The second line consists of n positive integers, d1, d2, …, dn (di ≤ 100000), which is the difficulty value of each task. The third line consists of n positive integers, p1, p2, …, pn (pi ≤ 100), which is the profit that each task may bring to Aggie.
OutputFor each test case, output a single numberwhich is the largest profits that Aggie may gain.
Sample Input1
5
3 4 5 1 2
1 1 1 2 2
Sample Output4
Source“科林明伦杯”哈尔滨理工大学第七届程序设计团队赛
题意为,有n个任务,每个任务有各自的价值和利润,必须按顺序做任务并且下一步只能做价值比以前高的任务,问能带来的最大利润。
带权上升子序列权值和的最大值,带权LIS,不过我首先想到的是用线段树维护DP过程,后来觉得好像树状数组也可以,随性来了一发。
与普通树状数组不同的是,在单点更新和区间查询时,维护过程为寻找目前状态所能得到的最大值,也就是在增加数据时,看一遍后面跟这个点有关的点的值是否小于这个数据,如果小于则换掉,在差区间和时,也是寻找前方所存在的最大值的过程。
#include <bits/stdc++.h> using namespace std;const int N = 1e5+10;int t, n, ans, mx;int d[N], p[N], tree[N], dp[N];void add(int pos, int val) {while(pos <= mx) {tree[pos] = max(tree[pos], val);pos += pos&(-pos);}}int maxx(int pos) {int res = 0;while(pos) {res = max(res, tree[pos]);pos -= pos&(-pos);}return res;}int main() {scanf("%d", &t);while(t--) {ans = mx = 0;scanf("%d", &n);memset(tree, 0, sizeof(tree));for(int i = 1; i <= n; i++) {scanf("%d", &d[i]);mx = max(mx, d[i]);}for(int i = 1; i <= n; i++) scanf("%d", &p[i]);for(int i = 1; i <= n; i++) {dp[i] = maxx(d[i]-1) + p[i];ans = max(ans, dp[i]);add(d[i], dp[i]);}printf("%d\n", ans);}}
- 科林明伦杯哈尔滨理工大学第七届程序设计团队赛-Aggie’s Tasks
- “科林明伦杯”哈尔滨理工大学第七届程序设计团队赛 I.Aggie’s Tasks(带权的LIS)
- “科林明伦杯”哈尔滨理工大学第七届程序设计团队赛 I.Aggie’s Tasks(带权的LIS)
- 科林明伦杯哈尔滨理工大学第七届程序设计团队赛-水题*2
- “科林明伦杯”哈尔滨理工大学第七届程序设计团队赛 G.Sorting(贪心,思路)
- 科林明伦杯”哈尔滨理工大学第七届程序设计团队赛G
- “科林明伦杯”哈尔滨理工大学第七届程序设计团队赛 A. An Easy Geometry Problem(计算几何)
- "科林明伦杯"哈尔滨理工大学第六届程序设计团队赛
- "科林明伦杯"哈尔滨理工大学第六届程序设计团队赛(12.10)
- "科林明伦杯"哈尔滨理工大学第六届程序设计团队赛总结
- "科林明伦杯"哈尔滨理工大学第六届程序设计团队赛(流水账)
- "科林明伦杯"哈尔滨理工大学第六届程序设计团队赛 HRBUST 2315 Time(水)
- "科林明伦杯"哈尔滨理工大学第六届程序设计团队赛总结
- 哈尔滨理工大学第六届程序设计团队赛网络同步赛
- 哈尔滨理工大学第六届程序设计团队赛—H
- 哈尔滨理工大学第六届程序设计团队赛—C
- 哈尔滨理工大学第六届程序设计团队赛—D
- "尚学堂杯"哈尔滨理工大学第七届程序设计竞赛
- redis ae.c/acMain()
- JMS(一)--JMS基本概念
- IDEA spring boot+jsp 404
- Thread 匿名内部类
- jetty 6.x https访问双向认证配置方法
- 科林明伦杯哈尔滨理工大学第七届程序设计团队赛-Aggie’s Tasks
- github使用问题记录及解决办法
- Android adapter.notifyDataSetChanged失效的可能原因
- android 打造真正的下拉刷新上拉加载recyclerview(四):自动加载和其他封装
- 杭电acm1272 小希的迷宫
- 不同局域网内经Internet的P2P通信技术 tcp
- 测试庖丁解牛分词工具
- java.util.zip.ZipException: error in opening zip file
- Xshell 出现中文乱码,你需要这样做!