• SDUSTOJ 1800 LIS(最长上升子序列不同位置个数)


    Description

    给定一个长度为n的序列(n <= 1000) ,记该序列LIS(最长上升子序列)的长度为m,求该序列中有多少位置不相同的长度为m的严格上升子序列。

    Input

    先输入一个T,表明下面会有几组数据。
    每组数据先输入一个n,表明数组大小。
    下面一行有n个数代表该数组,且 1<=a[i]<=n;

    Output

    输出为一行,只需输出上述要求的个数(输出保证结果小于2^31)。

    Sample Input

    3
    2
    1 2
    4
    1 2 4 4
    5 
    1 2 3 4 5

    Sample Output

    1
    2
    1
    思路:
    还是第三届山科校赛的题,这个题算是比较水了
    就是在求最长上升子序列的时候用数组维护一个以当前位置为末尾的最长上升子序列的不同位置个数之和
    然后用另一个数组维护一个当前长度自序列的总和
    依旧是n^2的复杂度
    /* ***********************************************
    Author        :devil
    Created Time  :2016/4/26 21:58:52
    ************************************************ */
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <cmath>
    #include <stdlib.h>
    using namespace std;
    const int N=1010;
    int dp[N],a[N],b[N],c[N];
    int main()
    {
        //freopen("in.txt","r",stdin);
        int t,n;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            for(int i=1; i<=n; i++)
                scanf("%d",&a[i]);
            int ma=0;
            memset(c,0,sizeof(c));
            c[1]=n;
            for(int i=1; i<=n; i++)
            {
                b[i]=dp[i]=1;
                for(int j=1; j<i; j++)
                {
                    if(a[i]>a[j]&&dp[i]<dp[j]+1)
                    {
                        dp[i]=dp[j]+1;
                        b[i]=b[j];
                    }
                    else if(a[i]>a[j]&&dp[i]==dp[j]+1) b[i]+=b[j];
                }
                if(dp[i]>1) c[dp[i]]+=b[i];
                ma=max(ma,dp[i]);
            }
            printf("%d
    ",c[ma]);
        }
        return 0;
    }


  • 相关阅读:
    第二章 Google guava cache源码解析1--构建缓存器
    第十一章 AtomicInteger源码解析
    JVM虚拟机(五):JDK8内存模型—消失的PermGen
    JVM虚拟机(四):JVM 垃圾回收机制概念及其算法
    Java中RunTime类介绍
    JVM虚拟机(三):参数配置
    ZooKeeperEclipse 插件
    zookeeper(五):Zookeeper中的Access Control(ACL)
    zookeeper(六):Zookeeper客户端Curator的API使用详解
    Java并发编程(九):拓展
  • 原文地址:https://www.cnblogs.com/d-e-v-i-l/p/5436755.html
Copyright © 2020-2023  润新知