2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】
2021-07-14 22:05
标签:south 大学生 space sizeof play 思路 mis lin splay 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 有N个村庄 [ 横纵坐标为 x , y ( x , y >= 1 && x , y
离散化 +排序+树状数组维护区间最大值 坐标 x, y 的范围太大,而节点范围还可以,所以不妨离散化一波(听说实际测试数据范围没有到1e9,出题人就料定我们没有这个胆)。 一开始用传统 dp ,状态转移很好想,但很明显会超时,交了两波TLE果断自闭。 这道题是正确打开方式是线段树或者树状数组维护区间最大值,而这里的区间是 y 的区间。然后通过前一行的最优值去转移得到当前行的最优值,不过排序顺序需要注意,因为只有左下方的可以转移过来所以当 x 相同时,优先处理 y 大的。 AC code: 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】 标签:south 大学生 space sizeof play 思路 mis lin splay 原文地址:https://www.cnblogs.com/ymzjj/p/9537617.htmlYJJ‘s Salesman
Total Submission(s): 919 Accepted Submission(s): 290Problem Description
One day, he is going to travel from city A to southeastern city B. Let us assume that A is (0,0) on the rectangle map and B (109,109). YJJ is so busy so he never turn back or go twice the same way, he will only move to east, south or southeast, which means, if YJJ is at (x,y) now (0≤x≤109,0≤y≤109), he will only forward to (x+1,y), (x,y+1) or (x+1,y+1).
On the rectangle map from (0,0) to (109,109), there are several villages scattering on the map. Villagers will do business deals with salesmen from northwestern, but not northern or western. In mathematical language, this means when there is a village k on (xk,yk) (1≤xk≤109,1≤yk≤109), only the one who was from (xk?1,yk?1) to (xk,yk) will be able to earn vk dollars.(YJJ may get different number of dollars from different village.)
YJJ has no time to plan the path, can you help him to find maximum of dollars YJJ can get.
Input
In each case, the first line of the input contains an integer N (1≤N≤105).The following N lines, the k-th line contains 3 integers, xk,yk,vk (0≤vk≤103), which indicate that there is a village on (xk,yk) and he can get vk dollars in that village.
The positions of each village is distinct.
Output
题目大意:
解题思路:
1 #include
上一篇:排序算法之希尔排序
下一篇:python学习随笔_简介
文章标题:2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】
文章链接:http://soscw.com/index.php/essay/105290.html