YJJ's Salesman

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1383    Accepted Submission(s): 483

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 way to destination.
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
The first line of the input contains an integer T (1≤T≤10),which is the number of 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 is 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
 
int a[N],x[N];
int t,n,ret,ans;
void update(int i,int num){
while(i<=n){
a[i]=max(a[i],num);
i+=lowbit(i);
}
}
int query(int n)
{
int ans=;
while(n>)
{
ans=max(ans,a[n]);
n-=lowbit(n);
}
return ans;
}
struct M{
int x,y,ux,uy,w;
}mm[N];
bool cmp3(M a,M b){
if(a.y!=b.y) return a.y<b.y;
return a.x>b.x;
//按列的话要按上式排序,x的排序不能错
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
mem(a,);
gep(i,,n){
scanf("%d%d%d",&mm[i].x,&mm[i].y,&mm[i].w);
x[i]=mm[i].x;
} //都要排序
sort(x+,x++n);//为了lower_bound
sort(mm+,mm++n,cmp3);//为了下面的更新
ret=,ans=;
gep(i,,n){//按列
int k=lower_bound(x+,x++n,mm[i].x)-x;//1~N
ret=query(k-)+mm[i].w;//1~k-1 的最大值+ mm[i].w
update(k,ret);
ans=max(ans,ret);
}
printf("%d\n",ans);
}
return ;
}

HDU 6447的更多相关文章

  1. 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...

  2. HDU 6447 - YJJ's Salesman - [树状数组优化DP][2018CCPC网络选拔赛第10题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 Problem DescriptionYJJ is a salesman who has tra ...

  3. HDU 6447 YJJ’s Salesman (树状数组 + DP + 离散)

    题意: 二维平面上N个点,从(0,0)出发到(1e9,1e9),每次只能往右,上,右上三个方向移动, 该N个点只有从它的左下方格点可达,此时可获得收益.求该过程最大收益. 分析:我们很容易就可以想到用 ...

  4. 2018CCPC网络赛

    A - Buy and Resell HDU - 6438 The Power Cube is used as a stash of Exotic Power. There are nn cities ...

  5. BIT+DP

    2018CCPC网络赛 J - YJJ's Salesman HDU - 6447 YJJ is a salesman who has traveled through western country ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. Php对象及对象特性篇

    前言 以前写C++最多,大二课上学过Java.现在也差不多还给老师了.现在决定针对php重新梳理一遍,夯实基础,设计模式学起来应该会更加得心应手吧. 介绍 对象作为数据和功能代码的集合,是程序开发和代 ...

  2. HDU4089(概率dp)

    题解 要点: 1.转移方程分三段,这个……有点复杂但是还好吧……大概就是求啥设啥,然后只通过可行的状态过来.在纸上记一记. 2.每层里面必须先求dp[i][i],简直就是我求我自己……用类似进制数那种 ...

  3. 调试PHP

    echo "<br/>"; print_r($array);

  4. centos设置ssh免密码登陆

    准备工作:    1.确认本机sshd的配置文件(需要root权限) $ gedit /etc/ssh/sshd_config 找到以下内容,并去掉注释符”#“ RSAAuthentication y ...

  5. Y2分班考试 笔试题总结

    1. 此题编译错误  base无法点出methodB()方法 2. 第二题选C 3.此题选D:正确的输出级别为fatal>error>warn>info>debug 4. 此题 ...

  6. 自定义orgmode中加粗字体的颜色

    自定义orgmode中加粗字体的颜色 Table of Contents 1. orgmode中加粗字体的默认处理 2. 设置设置加粗字体的颜色 1 orgmode中加粗字体的默认处理 在orgmod ...

  7. 洛谷 P2347 砝码称重 != codevs 2144

    题目描述 设有1g.2g.3g.5g.10g.20g的砝码各若干枚(其总重<=1000), 输入输出格式 输入格式: 输入方式:a1 a2 a3 a4 a5 a6 (表示1g砝码有a1个,2g砝 ...

  8. Fedora CentOS Red Hat中让vim支持语法高亮设置

    Fedora / CentOS / Red Hat这三个系统里默认的vi是没有语法高亮显示的,白色的字体看起来很不舒服. 首先用命令行cat /etc/os-release查看当前linux系统的类型 ...

  9. 单调栈2 POJ3250 类似校内选拔I题

    这个题再次证明了单调栈的力量 简单 单调栈 类似上次校内选拔消砖块 一堆牛面朝右排 给出从左到右的 问每个牛的能看到前面牛发型的个数之和 //re原因 因为在执行pop的时候没有判断empty 程序崩 ...

  10. Webpack2 视频教程

      原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」.Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本 ...