Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we ca…
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities a…
HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和rich city,求解最多能修几条不相交的路.此题可以转化为LIS问题.转化过程如下: 数据中有2列,为方便表述,暂且叫做第一列和第二列. 1.若第一列是是递增的(给出的2个样例都是递增的),那么要想尽可能多的做连线,则那么就需要找出第二列中最长的递增子序列,若出现非递增的序列,那么连线后一定会相交.…
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23467    Accepted Submission(s): 6710 Problem Description JGShining's kingdom consists of 2n(n is no mo…
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14635    Accepted Submission(s): 4158 Problem Description JGShining's kingdom consists of 2n(n is no mo…
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13646    Accepted Submission(s): 3879 Problem Description JGShining's kingdom consists of 2n(n is no mor…
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27358    Accepted Submission(s): 7782 Problem Description JGShining's kingdom consists of 2n(n is no mor…
点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市,所以要修路,但是不能从富有的修到富有的也不能从贫穷的修到贫穷的,只能从富有的修到贫穷的,但是不允许修交叉路,所以问你最多能修多少条路. 题意 :这个题一开始我瞅了好久都没觉得是DP,后来二师兄给讲了一下才恍然大悟.其实就是用到了DP中的那个最长上升子序列,把题中贫穷城市的坐标当成数组的下标,跟其相连…
#include<iostream> using namespace std; //BFS+优先队列(打印路径) #define N 500005 int c[N]; int dp[N]; //dp[i]保存的是长度为i的最长不降子序列的最小尾元素 int BS(int n,int x) //二分查找下标,当x比全部元素小时下标为1,比全部元素大时下标为n+1. { int low,high,mid; low=1,high=n; while(low<=high) { mid=(low+h…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p排序也是一样的.但这题的n的范围是5*10^5次方,所以用n^2算法求 最长上升子序列肯定不行,下面简单介绍一下nlogn时间内求的方法: 从序列里面每次插入一个数,插入到另外一个数组里面,这个数组初始状态是空的,插入一个数时,如果这个数比这个数组里面的任何一个数都大,则直接插入到最后面,否则判断这…