HDU 6447-YJJ ' s salesman-[Tree array optimization DP][2018CCPC network tryouts 10th]

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=6447

Problem Description
YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the the-to destination.
One day, he's going to travel from city A to southeastern city B. Let us assume, 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, he'll only move to east, south or southeast, which means, If YJJ is at (x, y) Now (0≤x≤109,0≤y≤109), he would 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 is several villages scattering on the map. Villagers'll does business deals with salesmen from Northwestern, but not northern or western. In mathematical language, this means if there is a village K on (Xk,yk) (1≤xk≤109,1≤yk≤109), only xk?1,yk?1) to (Xk,yk) is able to earn VK dollars. (Yjj may get different number of dollars from different village.)
YJJ have no time to plan the path, can-you-help him to find maximum of dollars yjj can get.

Input
The first line of the input contains a integer T (1≤t≤10), which is the number of the test cases.
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 are a village on ( Xk,yk) and he can get VK dollars in that village.
The positions of each village is distinct.

Output
The maximum of dollars yjj can get.

Sample Input
1
3
1 1 1
1 2 2
3 3 1

Sample Output
3

Source
2018 Chinese college student Program design contest-Online Tryouts

Test instructions

From $ (0,0) $ to $ (10^9,10^9) $ go, each time only from $\left ({x, y} \right) $ go to $\left ({× + 1,y} \right) $ or $\left ({y + x + 1} \right) $ or $\ Left ({x + 1,y + 1} \right) $, cannot go back, cannot walk the road of repetition,

Some villages are distributed on the map, giving the village coordinates $\left ({x, y} \right) $ and $v $ value, and only when you walk to the village from $\left ({x-1,y-1} \right) $ Can you get $v $ for the maximum amount of $v $ you can get.

Exercises

Obviously, assuming I went to a certain village $\left ({x_0,y_0} \right) $, then only in $x \ge X_0 + 1$ and $y \ge y_0 + 1$ in the range of villages, can make my $v $ value further increase,

In other words, I went to a village $\left ({x_0,y_0} \right) $, my last "meaningful" village must be in the range of $x \le x_0-1$ and $y \le y_0-1$,

So I'm going to find a village $x \le x_0-1$ and $y \le y_0-1$, and when I walk to the village, I get the largest $v $ value,

Therefore, we assume that $DP \left[I \right]$ the largest $v $ that can be obtained when walking to the village $i $, the state transition equation is:

$DP \left[i \right] = \max \left ({dp\left[J \right] + v\left[i \right]} \right) $, where the village $j $ coordinates $\left ({x, y} \right) $ satisfies $x \le x_0-1$ and $y \le y_0-1$

So, for each village, to be able to $O \left ({\log n} \right) $ to get the maximum value within a range, but also to be able to $O the maximum value in a region of \left ({\log n} \right), naturally think of the tree array ...

HDU 6447-YJJ ' s salesman-[Tree array optimization DP][2018CCPC network tryouts 10th]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.