题意

给出长度为n的序列,问这个序列中有多少个长度为m的单调递增子序列。

\(1\le M\le N\le 1000\)

分析

用F[i,j]表示前j个数构成以Aj为结尾的数列中,长度为i的严格递增子序列有多少个

\[F[i,j]=\sum_{k<j\wedge A_k<A_j}F[i-1,k]
\]

复杂度\(O(mn^2)\)。

观察到决策集合的变化一是只增不减,二是有一个前缀范围,用树状数组维护转移即可。时间复杂度\(O(mn\log n)\)

代码

#include<iostream>
#include<algorithm>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;rg char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') w=-1;ch=getchar();}
while(isdigit(ch)) data=data*10+ch-'0',ch=getchar();
return data*w;
}
template<class T>il T read(rg T&x) {return x=read<T>();}
typedef long long ll;
using namespace std; co int N=1e3+1,INF=0x3f3f3f3f,mod=1e9+7;
int n,m,a[N],b[N],c[N],f[N][N],num;
void add(int x,int y){
for(;x<=n+1;x+=x&-x)
c[x]=(c[x]+y)%mod;
}
int ask(int x){
int ans=0;
for(;x;x-=x&-x)
ans=(ans+c[x])%mod;
return ans;
}
void The_Battle_of_Chibi(){
read(n),read(m);
for(int i=1;i<=n;++i) b[i]=read(a[i]);
sort(b+1,b+n+1);
for(int i=1;i<=n;++i) a[i]=lower_bound(b+1,b+n+1,a[i])-b+1;
a[0]=f[0][0]=1;
for(int i=1;i<=m;++i){
fill(c+1,c+n+2,0);
add(1,f[i-1][0]);
for(int j=1;j<=n;++j){
f[i][j]=ask(a[j]-1);
add(a[j],f[i-1][j]);
}
}
int ans=0;
for(int i=1;i<=n;++i) ans=(ans+f[m][i])%mod;
printf("Case #%d: %d\n",++num,ans);
}
int main(){
for(int t=read<int>();t--;) The_Battle_of_Chibi();
return 0;
}

HDU5542 The Battle of Chibi的更多相关文章

  1. hdu5542 The Battle of Chibi【树状数组】【离散化】

    The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  2. hdu5542 The Battle of Chibi[DP+BIT]

    求给定序列中长度为M的上升子序列个数.$N,M<=1000$. 很容易想到方法.$f[i,j]$表示以第$i$个数结尾,长度为$j$的满足要求子序列个数.于是转移也就写出来了$f[i][j]+= ...

  3. 南阳ccpc C题 The Battle of Chibi && hdu5542 The Battle of Chibi (树状数组优化+dp)

    题意: 给你一个长度为n的数组,你需要从中找一个长度为m的严格上升子序列 问你最多能找到多少个 题解: 我们先对原序列从小到大排序,排序之后的序列就是一个上升序列 这里如果两个数相等的话,那么因为题目 ...

  4. The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542

    The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  5. 2015南阳CCPC C - The Battle of Chibi DP

    C - The Battle of Chibi Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Cao Cao made up a ...

  6. HDU - 5542 The Battle of Chibi(LIS+树状数组优化)

    The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...

  7. CDOJ 1217 The Battle of Chibi

    The Battle of Chibi Time Limit: 6000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Othe ...

  8. 2015南阳CCPC C - The Battle of Chibi DP树状数组优化

    C - The Battle of Chibi Description Cao Cao made up a big army and was going to invade the whole Sou ...

  9. The Battle of Chibi(数据结构优化dp,树状数组)

    The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...

随机推荐

  1. EmailHelper

    注:个人邮箱发送时需要将邮箱密码设置为邮件授权码 邮件发送帮助类一: public class EmailHelper { /// <summary> /// 发送邮件 /// </ ...

  2. robot framework学习二-----元素定位

    文章摘自:https://www.cnblogs.com/fnng/p/3901391.html 不要误认为Robot framework 只是个web UI测试工具,更正确的理解Robot fram ...

  3. java笔记 -- java简单结构代码解析及注释

    结构代码解析 public class FirstSample { public static void main(String[] args) { System.out.println(2.0-1. ...

  4. ehcache 简介和基本api使用

    文章转载自: https://blog.csdn.net/zhouzhiwengang/article/details/59838105 1.ehcahce简介 在开发高并发量,高性能的网站应用系统时 ...

  5. Anaconda 创建环境

    2019-03-25 17:10:51 Anaconda 给不同的项目创建不同的环境真的非常重要,最近在使用flask的时候在base环境中安装flask-bootstrap,竟然将我原本的py3.7 ...

  6. spark的二次排序

    通过scala实现二次排序 package _core.SortAndTopN import org.apache.spark.{SparkConf, SparkContext} /** * Auth ...

  7. [spring源码] 小白级别的源码解析IOC容器的依赖注入(三)

    上一篇介绍了ioc容器的初始化过程,主要完成了ioc容器建立beanDefinition数据映射.并没有看到ioc容器对bean依赖关系进行注入. 接口getbean就是出发依赖注入发生的地方.下面从 ...

  8. Mysql 监控脚本

    cat mysql_status_output.py #coding=utf-8import jaydebeapiimport sysimport pymysqlimport osfrom prome ...

  9. Java servlet 实现的简易购物车

    首页 2.购买页 3.购物车页 1. 首页代码 发送一个post请求 <!DOCTYPE html><html lang="en"><head> ...

  10. 在windows下安装nvm并管理nodejs版本

    不得不说,nodejs的nvm工具跟python下的mkvirtualenv 工具很像.作为立志成为伪全栈的我来说,玩玩nodejs是必不可少的.nodejs 有很多种的安装方式,下面我用nvm的方式 ...