hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分】
来源:互联网 发布:公司公司招聘数据 编辑:程序博客网 时间:2024/06/05 18:33
题目链接:http://acm.acmcoder.com/showproblem.php?pid=1025
题意:本求最长公共子序列,但数据太多。转化为求最长不下降子序列。太NB了。复杂度n*log(n).
解法:dp+二分
代码:
#include <stdio.h>#include <string.h>#include <vector> #include <string> #include <algorithm> #include <iostream>#include <iterator>#include <fstream>#include <set>#include <map>#include <math.h>using namespace std;const int MAXN = 500010;int n, pos;int a[MAXN];int dp[MAXN];int h, k;int search(int num,int low,int high){ int mid; while (low <= high) { mid = (low + high) / 2; if (num >= dp[mid]) low = mid + 1; else high = mid - 1; } return low;}int main(){ int cases = 1; while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) { scanf("%d%d", &h, &k); a[h] = k; } memset(dp, 0, sizeof(dp)); dp[0] = -1; dp[1] = a[1]; int len = 1; // n*log(n) 求解 for (int i = 2; i <= n; i++) { if (a[i] >= dp[len]) { len = len + 1; dp[len] = a[i]; } else { pos = search(a[i],1,len); dp[pos] = a[i]; } } printf("Case %d:\n",cases++); if (len == 1) printf("My king, at most %d road can be built.\n\n",len); else printf("My king, at most %d roads can be built.\n\n",len); } return 0;}
0 0
- HDU 1025 Constructing Roads In JGShining's Kingdom DP+二分
- hdu 1025 Constructing Roads In JGShining's Kingdom (DP + 二分)
- hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分】
- HDU-1025-Constructing Roads In JGShining's Kingdom【LIS】【二分】
- HDU 1025 Constructing Roads In JGShining's Kingdom (DP)
- 【DP|LIS】HDU-1025 Constructing Roads In JGShining's Kingdom
- hdu 1025 Constructing Roads In JGShining's Kingdom(DP)
- HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)
- Hdu 1025 Constructing Roads In JGShining's Kingdom(DP)
- HDU 1025:Constructing Roads In JGShining's Kingdom(DP)
- hdu1025 Constructing Roads In JGShining's Kingdom(二分+dp)
- hdu1025 Constructing Roads In JGShining's Kingdom(DP+二分)
- HDU1025:Constructing Roads In JGShining's Kingdom(LIS(dp+二分))
- hdu1025 Constructing Roads In JGShining's Kingdom(DP+二分)
- hdu Constructing Roads In JGShining's Kingdom
- HDOJ 1025 Constructing Roads In JGShining's Kingdom (DP)
- hdu 1025Constructing Roads In JGShining's Kingdom(LIS)
- hdu 1025 Constructing Roads In JGShining's Kingdom
- jQuery中的小知识:first-child和first-of-type的区别
- 只获得当前一个对象数据实现
- Java语言描述:分支限界法之01背包问题
- linux下安装mysql5.5.x的过程笔记
- 《机器学习实战》学习笔记——kNN算法
- hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分】
- Java反射机制详解。
- 顺手笔记---javac,javap,javah
- nginx + FastDFS分布式文件服务器搭建及配置
- Android:横行滚动且隔行变色的ListView控件
- C++对象模型:第2章(1)-构造函数
- intent常见应用
- HTTP缓存技术,304(Not Modified)和200(from cache)有何区别?
- DXP2004 warning / error/注意事项