HDU 1950 Bridging signals (最长递增子序列(nlogn算法)
2017-02-24 17:21
295 查看
题意:题目不怎么好读,好多生僻单词,和图一对比就清楚了,就是端口对接,在连线不交叉的情况下,最多连线条数。
思路:最长递增子序列(nlogn算法),和hdu1025思路一样。
AC代码如下;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=4e4+10;
int p;
int mp[maxn];
int t[maxn];
int len;
int binary_serch1(int i){
int left=1,right=len;
while(left<=right){
int mid=(left+right)/2;
if(mp[i]>t[mid])
left=mid+1;
else right=mid-1;
}
return left;
}
int main(){
int n;
scanf("%d",&n);
while(n--){
scanf("%d",&p);
for(int i=1;i<=p;i++)
scanf("%d",&mp[i]);
t[1]=mp[1];
len=1;
for(int i=2;i<=p;i++){
if(mp[i]>t[len]){
t[++len]=mp[i];
}
else {
int k=binary_serch1(i);
t[k]=mp[i];
}
}
printf("%d\n",len);
}
return 0;
}
思路:最长递增子序列(nlogn算法),和hdu1025思路一样。
AC代码如下;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=4e4+10;
int p;
int mp[maxn];
int t[maxn];
int len;
int binary_serch1(int i){
int left=1,right=len;
while(left<=right){
int mid=(left+right)/2;
if(mp[i]>t[mid])
left=mid+1;
else right=mid-1;
}
return left;
}
int main(){
int n;
scanf("%d",&n);
while(n--){
scanf("%d",&p);
for(int i=1;i<=p;i++)
scanf("%d",&mp[i]);
t[1]=mp[1];
len=1;
for(int i=2;i<=p;i++){
if(mp[i]>t[len]){
t[++len]=mp[i];
}
else {
int k=binary_serch1(i);
t[k]=mp[i];
}
}
printf("%d\n",len);
}
return 0;
}
相关文章推荐
- hdu杭电1950 Bridging signals【最大递增子序列(不连续)】
- hdu 5748 Bellovin(BestCoder Round #84——最长递增子序列)
- HDUOJ 1950 - Bridging signals(DP + 二分查找:最长递增子序列LIS【nlogn算法】)
- HDU - 1087 Super Jumping! Jumping! Jumping!(最长递增子序列)
- 最长递增子序列 ( LIS )——The All-purpose Zero ( HDU 5773 ) ( 2016 Multi-University Training Contest 4 1010 )
- HDU 1950 Bridging signals 最长公共子序列(LIS)nlogn算法实现
- hdu 1950 Bridging signals 最长上升序列nlogn
- HDU 1950-最长上升子序的nlogn算法
- hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
- HDU 1069 Monkey and Banana (类似最长递增子序列)
- HDU 1025 Constructing Roads In JGShining's Kingdom 最长子序列的nlogn算法
- HDU 1950(Bridging signals)最长不降子序列nlogn
- POJ 1631 HDU 1950(最长上升子序列问题)
- HDU 1950 Bridging signals【最长上升序列】
- //hdu 1231 最大连续子序列 (动态规划)
- (HDU 1160) FatMouse's Speed dp (最长递增子序列 , 两个因素决定)
- 最长递增子序列(Longest Increase Subsequence)
- hdu 1231最长子序列和
- 浙大pat | 牛客网 1034 Favorite Color Stripe (30) 最长递增子序列 DP
- HDU 1231 最大连续子序列