HDU 1025-最长上升子序列

来源:互联网 发布:人工智能的龙头股 编辑:程序博客网 时间:2024/06/05 19:02

题目链接

包装了的最长上升子序列题目

#include <iostream>  #include <cstring>#include <cstdio>#include <algorithm>#include <string>#include <string.h>#include <cmath>#include <sstream>#include <set>#include <map>#include <functional>#include <queue>#include <vector>using namespace std;const int maxn = 500010;const int INF=0x7fffffff;int arr[maxn], d[maxn];int n, res, pos;int main(){    int Case=0;    while (~scanf("%d",&n))    {        res = -1, pos = 0;        for(int i=0;i<=n;i++)            d[i]=INF;        for (int i = 0; i < n; i++)        {            int a,b;            scanf("%d%d",&a,&b);            arr[a]=b;        }        for (int i = 1; i <= n; i++)        {                    *lower_bound(d, d + n, arr[i]) = arr[i];        }                   pos=lower_bound(d, d + n, INF)-d;        printf("Case %d:\n",++Case);        if(pos==1)                                 printf("My king, at most 1 road can be built.\n\n");        else            printf("My king, at most %d roads can be built.\n\n",pos);    }}
原创粉丝点击