• 题意:给你一组数,求最长的严格上升子序列及个数(mod 1e9+7)

  • 题解:用动态规划来求LIS,记\(dp[i]\)是数组中第i个位置上的数的LIS最优解,我们遍历一遍原数组,然后找i位置前的LIS,如果\(a[j]<a[i]\)并且\(dp[j]+1>dp[i]\)那么当前i位置的最优解就应该更新成\(dp[j]+1\).然后我们再记一个\(res[i][length]\),表示i位置上长度为length的LIS的个数.最后统计一下长度最长的子序列有多少个就行了.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<long,long> PLL; int t;
    int n,a[N];
    ll res[2000][2000];
    int dp[N]; int main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
    cin>>n;
    me(res,0,sizeof(res));
    for(int i=1;i<=n;++i){
    cin>>a[i];
    dp[i]=1;
    res[i][1]=1;
    }
    for(int i=1;i<=n;++i){
    for(int j=1;j<i;++j){
    if(a[j]<a[i]){
    dp[i]=max(dp[i],dp[j]+1);
    res[i][dp[j]+1]=(res[i][dp[j]+1]+res[j][dp[j]])%mod;
    }
    }
    }
    sort(dp+1,dp+1+n);
    ll cnt=0;
    for(int i=1;i<=n;++i){
    cnt=(cnt+res[i][dp[n]])%mod;
    }
    printf("%d %lld\n",dp[n],cnt);
    }
    return 0;
    }

NCD 2019 C. Hasan and his lazy students的更多相关文章

  1. NCD 2019 M. NCD Salary

    题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0. 题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道: ...

  2. NCD 2019 H. Mr. Hamra and his quantum particles

    题意:给你n个数,有m次操作,每次使得两个数相连接,询问q次,问某两个数是否连接在一起. 题解:这其实是一道并查集的裸题,这里就不再多说了,写个路径压缩的find函数即可. 代码: #include ...

  3. 【POJ2094】【差分序列】Angry Teacher

    Description Mr. O'Cruel is teaching Math to ninth grade students. Students of course are very lazy, ...

  4. 线段树+lazy标记 2019年8月10日计蒜客联盟周赛 C.小A的题

    题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r] ...

  5. Lazy<T>在Entity Framework中的性能优化实践(附源码)

    在使用EF的过程中,导航属性的lazy load机制,能够减少对数据库的不必要的访问.只有当你使用到导航属性的时候,才会访问数据库.但是这个只是对于单个实体而言,而不适用于显示列表数据的情况. 这篇文 ...

  6. lazy instructor

    Description A math instructor is too lazy to grade a question in the exam papers in which students a ...

  7. 数据结构——POJ 1686 Lazy Math Instructor 栈的应用

    Description A math instructor is too lazy to grade a question in the exam papers in which students a ...

  8. POJ 1686 Lazy Math Instructor (模似题+栈的运用) 各种坑

    Problem Description A math instructor is too lazy to grade a question in the exam papers in which st ...

  9. Lazy Math Instructor

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3721   Accepted: 1290 Description A m ...

随机推荐

  1. 静默(命令行)安装oracle 11g

    CentOS 6 静默安装oracle 11g 我参考的这个,他非常详细:https://blog.csdn.net/JIANG123456T/article/details/77745892 我只是 ...

  2. SpringBoot配置文件(2)

    六.配置文件加载 SpringBoot 启动会扫描以下位置的application.properties或者application.yml文件作为SpringBoot的默认配置文件 file:./co ...

  3. 剑指offer之重建二叉树

    1.问题描述:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.        例如输入前序遍历序列pre {1,2,4,7,3,5,6, ...

  4. Assuming that agent dropped connection because of access permission

    Assuming that agent dropped connection because of access permission

  5. 【Linux】ABRT has detected 1 problem(s). For more info run: abrt-cli list --since 1548988705

    ------------------------------------------------------------------------------------------------- | ...

  6. C#使用OracleParameter操作数据库

    public static int GetScalar(string sql,params OracleParameter [] OracleParms) { using (OracleConnect ...

  7. ALV中的分隔条(SPLITTER_CONTROL)

    如上图,可以做成左右的分割,当然也可以做成上下的分割效果,在每个分割的容器内,显示各自的内容. 需要使用的class: cl_gui_splitter_container, cl_gui_custom ...

  8. mysql5.5 升级至5.7

    mysql5.5 升级至5.7 1.下载mysql5.7.32 官方下载地址 解压 tar xvf mysql.tar.gz mysql/ 2. 进入旧的mysql的bin目录下导出mysql的数据 ...

  9. 被集群节点负载不均所困扰?TKE 重磅推出全链路调度解决方案

    引言 在 K8s 集群运营过程中,常常会被节点 CPU 和内存的高使用率所困扰,既影响了节点上 Pod 的稳定运行,也会增加节点故障的几率.为了应对集群节点高负载的问题,平衡各个节点之间的资源使用率, ...

  10. 如何封装Promise对象?

    最近看到了一个有趣的Promise的方法,这里记录下来 <script> class MyPromise { constructor(executor) { // 初始化state赋值为p ...