poj1631 Bridging signals

思路:

LIS,二分。

实现:

 1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 int d[40010];
 5 int fuck(int x, int right)
 6 {
 7     int left = 0;
 8     int pos = -1;
 9     while (left <= right)
10     {
11         int middle = (left + right) / 2;
12         if (d[middle] >= x)
13         {
14             pos = middle;
15             right = middle - 1;
16         }
17         else
18         {
19             left = middle + 1;
20         }
21     }
22     return pos;
23 }
24 int main()
25 {
26     int t, n;
27     int temp;
28     cin >> t;
29     while (t--)
30     {
31         cin >> n;
32         int cnt = 0;
33         for (int i = 0; i < n; i++)
34         {
35             scanf("%d", &temp);
36             if (cnt == 0 || temp > d[cnt - 1])
37             {
38                 d[cnt++] = temp;
39             }
40             else
41             {
42                 int pos = fuck(temp, cnt - 1);
43                 d[pos] = temp;
44             }
45         }
46         printf("%d\n", cnt);
47     }
48     return 0;
49 }
时间: 2024-08-03 10:35:59

poj1631 Bridging signals的相关文章

POJ-1631 Bridging signals

题目大意:就是求最长的上升子序列,输出长度. 思路:LIS水题.就是题目描述的特别长. 1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #include<string.h> 5 using namespace std; 6 int a[40005]; 7 int dp[40005]; 8 int mx[40005]; 9 int INF=9999999; 10 int main

[POJ1631]Bridging signals (DP,二分优化)

题目链接:http://poj.org/problem?id=1631 就是求一个LIS,但是范围太大(n≤40000),无法用常规O(n²)的朴素DP算法,这时需要优化. 新加一个数组s[]来维护长度当LIS的长度为len时候需要的数组a中的最小数字的值,可以证明这个数组是严格单调递增的,因此可以二分确定每次枚举到a[i]的时候,a[i]在这个数组中所处的位置(下标),也就是a[i]数字时此时之前算过的LIS的长度.之后更新s数组和ans即可.对于最长下降自序列此方法同样适用,但是需要注意那时

zoj1986 Bridging Signals (dp,最长递增序列,LIS)

A - Bridging Signals Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practice ZOJ 1986 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designer

hdu----(1950)Bridging signals(最长递增子序列 (LIS) )

Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 667    Accepted Submission(s): 443 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland

POJ 1631 Bridging signals(LIS 二分法 高速方法)

Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10762   Accepted: 5899 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers

Bridging signals(求最长上升自序列nlogn算法)

Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2582    Accepted Submission(s): 1665 Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferlan

POJ 1631 Bridging signals &amp; 2533 Longest Ordered Subsequence

两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当前点不能作为当前最长子序列的最大值,则更新找到值为两者间的较小值. 2533 就是一个裸的最长上升子序列...这里就不多说了,直接dp就好... 1611: 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio

POJ 1631 Bridging signals(LIS+二分)

题目链接:POJ 1631 Bridging signals [题意]简单来说就是求最长上升子序列的长度. [思路]这道题目的数据规模有40000之多,如果用普通的动态规划O(n^2)肯定会超时的,所以要用上二分查找(又是二分啊,真牛逼)来进行优化,O(nlogn)的时间复杂度就OK了. 我使用了C++的lower_bound(ForwardIter first, ForwardIter last, const _Tp& val)函数.可以直接查找非递减序列[first, last)中的第一个大

POJ 1631 Bridging signals(LIS 二分 快速方法)

Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10762   Accepted: 5899 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers