ZOJ2283 Challenge of Wisdom(DP+二分求最长非上升子序列)
来源:互联网 发布:起点数据库 编辑:程序博客网 时间:2024/05/22 15:07
Link:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1283
Background
"Then, I want to know whether you're a wise boy!"
Problem
"I have a great deal of lands. They're divided into N*M grids (N, M <= 1,000,000,000). When you are in (x, y), you may move into (x+1, y) or (x, y+1). I have P (P <= 100,000) treasures in the lands; each time, you can pick up anything you like."
"Now, I'll give you a map of my treasures; tell me, wise boy, how many times you need to pick up all the treasures?"
Input
This problem contains multiple test cases.
Each test case begins with 3 integers N, M and P. then followed by P lines, each lines contains 2 numbers: x, y, representing the location of a treasure.
Output
For each test case, output the minimum times I need.
Sample Input
7 7 7
1 2
1 4
2 4
2 6
4 4
4 7
6 6
Sample Output
2
Contest: A Great Beloved and My Gate to Freedom
There is a cx, there is a love_cx.
Author: JIANG, Yanyan
Source: JIANG, Yanyan's Contest #2
AC code:
#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#include<map>#include<set>#include<vector>#define LL long long#define INF 0xfffffff#define PI acos(-1)#define EPS 1e-6using namespace std;struct node{int x;int y;}po[100010];bool cmp(node a,node b){if(a.x!=b.x)return a.x<b.x;elsereturn a.y<b.y;}int n,m,p;int dp[100010],num[100010],b[100010];void solve(){int i,MAX,le,ri,mid,ans,temp;b[1]=num[1];MAX=1;dp[1]=1;ans=0;for(i=2;i<=p;i++){if(num[i]<b[MAX]){MAX++;b[MAX]=num[i];dp[i]=MAX;}else{le=1;ri=MAX;while(le<=ri){mid=(le+ri)>>1;if(b[mid]<=num[i]){temp=mid;ri=mid-1;}else{le=mid+1;}}b[temp]=num[i];dp[i]=temp;}ans=max(ans,dp[i]);}printf("%d\n",ans);}int main(){//freopen("in.txt","r",stdin);int i;while(scanf("%d%d%d",&n,&m,&p)!=EOF){for(i=1;i<=p;i++){scanf("%d%d",&po[i].x,&po[i].y);}sort(po+1,po+p+1,cmp);for(i=1;i<=p;i++){num[i]=po[i].y;}solve();}return 0;}
- ZOJ2283 Challenge of Wisdom(DP+二分求最长非上升子序列)
- hdu 5125 二分nlogn求最长上升子序列(LIS)+dp
- 动态规划之编号动态规划:hdu 1025(dp+二分 求最长上升子序列)
- 二分求最长上升子序列
- 最长上升子序列,LIS<DP+二分>
- C - Mysterious Present(DP求最长上升子序列)
- 最长上升子序列 (二分 nlogn)
- 最长上升子序列 (二分)
- POJ 2533 求最长上升子序列长度 非DP 实现
- UVa 10534 - Wavio Sequence DP+最长上升子序列(严格上升)+二分查找(nlogn)
- 最长上升子序列(非连续)
- 最长上升子序列 (dp)
- 最长公共上升子序列 (dp)
- 最长上升子序列(DP)
- HDU1087(最长上升子序列DP)
- 最长上升子序列LIS(dp)
- 最长上升子序列(DP+模板)
- YTU3135--最长上升子序列(dp)
- Netty 中文教程 (二) Hello World !详解
- 注解
- 关于@property的一些用法
- 谈谈失败项目经历
- android 导入tensorflow lite
- ZOJ2283 Challenge of Wisdom(DP+二分求最长非上升子序列)
- 点云匹配和ICP算法概述
- 深度学习相关资料
- 多对多关系的多表关联查询
- es6类和对象
- 学习Linux C编程之进程控制编程
- vue中 router-link的简单使用
- #define和inline 的区别
- 应用程序无法正常启动0xc000007b