hdu6447 YJJ's Salesman】的更多相关文章

这个题意和数据范围一看就是离散化之后树状数组优化DP.给的"从左下方走上去才能拿到收益"的性质其实可以当成"必须从横纵坐标严格比某个点小的地方转移过来".1A了.~咸鱼产生了能翻身的错觉~ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=100005; int f[maxn]; int x[maxn…
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 919    Accepted Submission(s): 290 Problem Description YJJ is a salesman who h…
YJJ's Salesman 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…
思路:若用dp[i][j]表示走到(i,j)的最大值,那么dp[i][j] = max(dp[i - 1][j],dp[i][j - 1],dp[i - 1][j - 1] + v),显然O(n^2)超时.但是我们可以优化这个dp,我们用f[j]表示第i行第j列当前最大值,那么f[j] = max(f[j],f[k] + v[i][j]),k范围0~j - 1,所以我们只要用O(logn)找到f[k]就行了,显然可以用线段树维护f[j].我们先离散化,然后从上到下,从右到左排序,从右到左是因为我…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 Problem DescriptionYJJ 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…
题意: 二维平面上N个点,从(0,0)出发到(1e9,1e9),每次只能往右,上,右上三个方向移动, 该N个点只有从它的左下方格点可达,此时可获得收益.求该过程最大收益. 分析:我们很容易就可以想到用DP,假设这个位置是相对上一个位置的方向而来,但是复杂度达到N^2 ,这样是不行的: 我们可以利用坐标的信息,将所有的点离散化后,以x优先按小到大排序,按y按大到小排序,这时维护一个DP(i) ,表示第I列的最值. j=0→i−1j=0→i−1                           d…
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面.  1e5个点,问从(0,0)走到(1e9,1e9)的最大收益.  当你从(u-1,v-1)走到(u,v)时,你可以获得点(u,v)的权值. Solution:  十分详细了.  直接线段树区间最值.当然也可以树状数组,不能st表.  \(dp[i] = max(query\_max(0,dp[i]-1,1)+val[i] ,…
YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1258    Accepted Submission(s): 445 Problem Description YJJ is a salesman who has traveled through western country. YJJ is always o…
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物品,问最终赚的钱的最大值. solution 用两个堆来维护,一个堆维护已经找到卖家的,一个堆维护还没找到卖家的. 对于第\(i\)个地点,在已经找到卖家的堆里找出卖的钱的最小值,如果最小值小于\(a_i\),则将卖家换成\(i\),然后将原来的卖家放到没找到卖家的那里:如果最小值对于\(a_i\)…
A - Buy and Resell 题意:给出n个交易点,每次能够选择买或者卖,求获得最大利润 思路:维护两个优先队列,一个是卖,一个是替换,当价格差相同时,优先替换,因为次数要最少 #include <bits/stdc++.h> using namespace std; #define ll long long #define N 100010 int t, n; ll arr[N]; priority_queue <ll, vector <ll>, greater &…