zoukankan      html  css  js  c++  java
  • poj 1631 Bridging signals

    题目链接http://poj.org/problem?id=1631

    题目分类:动态规划

    代码

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<iostream>
    
    using namespace std;
    
    #define INF 0x3f3f3f3f
    
    int n;
    
    int a[50500];
    int dp[50500];
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int t;
        scanf("%d",&t);
    
        while(t--)
        {
            memset(a,0,sizeof(a));
            scanf("%d",&n);
            for(int i=0;i<n;i++)
            {
                scanf("%d",&a[i]);
            }
    
            fill(dp,dp+n,INF);
    
            for(int i=0;i<n;i++)
            {
                *lower_bound(dp,dp+n,a[i])=a[i];
            }
            printf("%d
    ",lower_bound(dp,dp+n,INF)-dp);
        }
        return 0;
    }

    下面的代码是超时的

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<iostream>
    
    using namespace std;
    
    #define INF 0x3f3f3f3f
    
    int n;
    
    int a[5050];
    int dp[5050];
    
    int main()
    {
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
        int t;
        scanf("%d",&t);
    
        while(t--)
        {
            memset(a,0,sizeof(a));
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
            }
    
            memset(dp,0,sizeof(dp));
    
            int res=0;
            for(int i=1;i<=n;i++)
            {
                dp[i]=1;
                for(int j=1;j<i;j++)
                {
                    if(a[j]<a[i])
                    {
                        dp[i]=max(dp[i],dp[j]+1);
                    }
                }
                res=max(dp[i],res);
            }
            printf("%d
    ",res);
        }
        return 0;
    }
    anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
  • 相关阅读:
    iphone6闪存检测
    knowledges address
    类linux系统/proc/sysrq-trigger文件功能作用
    iphone 6s pp助手 越狱
    C pointers
    ubuntu15.04 TLS
    ubuntu cenots 禁止本地登陆
    CentOS7
    CentOS7安全设置 yum-cron系统自动更新,firewalld防火墙简单使用
    SAS学习笔记之函数应用
  • 原文地址:https://www.cnblogs.com/gaoss/p/4943926.html
Copyright © 2011-2022 走看看