NCD 2019 C. Hasan and his lazy students
题意:给你一组数,求最长的严格上升子序列及个数(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的更多相关文章
- NCD 2019 M. NCD Salary
题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0. 题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道: ...
- NCD 2019 H. Mr. Hamra and his quantum particles
题意:给你n个数,有m次操作,每次使得两个数相连接,询问q次,问某两个数是否连接在一起. 题解:这其实是一道并查集的裸题,这里就不再多说了,写个路径压缩的find函数即可. 代码: #include ...
- 【POJ2094】【差分序列】Angry Teacher
Description Mr. O'Cruel is teaching Math to ninth grade students. Students of course are very lazy, ...
- 线段树+lazy标记 2019年8月10日计蒜客联盟周赛 C.小A的题
题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r] ...
- Lazy<T>在Entity Framework中的性能优化实践(附源码)
在使用EF的过程中,导航属性的lazy load机制,能够减少对数据库的不必要的访问.只有当你使用到导航属性的时候,才会访问数据库.但是这个只是对于单个实体而言,而不适用于显示列表数据的情况. 这篇文 ...
- lazy instructor
Description A math instructor is too lazy to grade a question in the exam papers in which students a ...
- 数据结构——POJ 1686 Lazy Math Instructor 栈的应用
Description A math instructor is too lazy to grade a question in the exam papers in which students a ...
- POJ 1686 Lazy Math Instructor (模似题+栈的运用) 各种坑
Problem Description A math instructor is too lazy to grade a question in the exam papers in which st ...
- Lazy Math Instructor
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3721 Accepted: 1290 Description A m ...
随机推荐
- LeetCode993. 二叉树的堂兄弟节点
题目 1 class Solution { 2 public: 3 TreeNode* r1;TreeNode* r2; 4 bool isCousins(TreeNode* root, int x, ...
- service代理模式及负载均衡
[root@k8s-master ~]# vim service.yaml apiVersion: v1 kind: Service metadata: name: my-service spec: ...
- DOI技术扫盲一
DOI: desktop office intergration 桌面办公软件集成简单的将,就是我们在Windows桌面中打开的办公软件(如:word,excel,pdf等等)可以在SAP系统进 ...
- PW6513高压40V的LDO芯片,SOT89封装
一般说明 PW6513系列是一款高精度,高输入电压,低静态电流,高速,低具有高纹波抑制的线性稳压器.输入电压高达40V,负载电流为在电压=5V和VIN=7V时高达300mA.该设备采用BCD工艺制造. ...
- html简单基础
标签语法 标签的语法: <标签名 属性1="属性值1" 属性2="属性值2"-->内容部分</标签名> <标签名 属性1=&quo ...
- 🙈 如何隐藏你的热更新 bundle 文件?
如果你喜欢我写的文章,可以把我的公众号设为星标 ,这样每次有更新就可以及时推送给你啦. 前段时间我们公司的一个大佬从一些渠道得知了一些小道消息,某国民级 APP 因为 Apple App Store ...
- 基于final shell的linux命令
final shell操作教程: 1.查看API实时日志:cd ../../data/log/api tail -100f anyAPI-server.log2.关闭日志:control+c3.恢复实 ...
- GraphQL 在酒店系统上的实践
https://mp.weixin.qq.com/s/Pmut13GYP-kwR2xm8fH-7Q
- How does Circus stack compare to a classical stack?
Frequently Asked Questions - Circus 0.15.0 documentation https://circus.readthedocs.io/en/latest/faq ...
- 「NOIP2009」最优贸易
「NOIP2009」最优贸易 「NOIP2009」最优贸易内存限制:128 MiB时间限制:1000 ms 题目描述C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意 ...