UESTC 1217 The Battle of Chibi
dp+树状数组优化。
dp[i][j]表示以a[i]结尾,最长上升序列长度为j的方案数。dp[i][j]=sum{dp[k][j-1]} 其中k<i&&a[k]<a[i]。 离散化后,可以用1000个树状数组维护。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi = acos(-1.0), eps = 1e-;
void File()
{
freopen("D:\\in.txt", "r", stdin);
freopen("D:\\out.txt", "w", stdout);
}
inline int read()
{
char c = getchar(); while (!isdigit(c)) c = getchar();
int x = ;
while (isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} int mod=;
const int maxn=;
int a[maxn],b[maxn],c[maxn][maxn],dp[maxn][maxn],ans;
int T,n,m; int lowbit(int x) { return x&(-x); }
int sum(int r,int p) { int res=; for(int i=p;i>;i=i-lowbit(i)) res=(res+c[r][i])%mod; return res; }
void update(int r,int p,int v) { for(int i=p;i<=;i=i+lowbit(i)) c[r][i]=(c[r][i]+v)%mod; } int main()
{
scanf("%d",&T); int cas=;
while(T--)
{
scanf("%d%d",&n,&m); memset(c,,sizeof c); ans=;
for(int i=;i<=n;i++) scanf("%d",&a[i]),b[i-]=a[i];
sort(b, b + n); int sz = unique(b, b + n) - b;
for(int i=;i<=n;i++) a[i]=lower_bound(b, b + sz, a[i])-b+;
for(int i=;i<=n;i++)
{
dp[i][]=; update(,a[i],dp[i][]);
for(int j=;j<=m;j++) { dp[i][j]=sum(j-,a[i]-); update(j,a[i],dp[i][j]); }
}
for(int i=;i<=n;i++) ans=(ans+dp[i][m])%mod;
printf("Case #%d: %d\n",cas++,ans);
}
return ;
}
UESTC 1217 The Battle of Chibi的更多相关文章
- ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) = ...
- DP+BIT(优化复杂度) UESTC 1217 The Battle of Chibi
题目传送门 题意:问n长度的序列,找出长度m的上升子序列的方案数. 分析:这个问题就是问:dp[i][j] = sum (dp[i-1][k]) (1 <= k <= n, a[k] &l ...
- CDOJ 1217 The Battle of Chibi
The Battle of Chibi Time Limit: 6000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...
- 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 ...
- 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 ...
- hdu5542 The Battle of Chibi【树状数组】【离散化】
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- 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 ...
- 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 ...
随机推荐
- Oracle SQL自带函数整理
数字函数 abs(n):用于返回数字n的绝对值 ceil(n):返回大于等于数字n的最小整数 floor(n):返回小于等于数字n的最大整数 mod(m,n):返回m/n数字相除后的余数,如果n=0, ...
- python学习之glob模块
如何批量获取文件路径 import glob import os def image_proc(): for files in glob.glob('/home/xxx/filename/*.png' ...
- laravel 日志
laravel学院的 http://laravelacademy.org/post/195.html 他人博客的 http://www.cnblogs.com/yjf512/p/4173261.htm ...
- 自动安装memcached服务端与PHP扩展Memcached
该脚本基于阿里云服务器安装脚本,并只能运用于centos / aliyun os,该脚本使用时,需要与阿里云安装脚本的install.sh放在同一目录下.有缘人切忌乱用: #! /bin/bash # ...
- RPD添加网址、变量
- jqGrid使用整理
jqGrid使用整理 jqGrid是一款处理表格展现的jQuery插件,支持分页.滚动加载.搜索.锁定.拖动等一系列对表格的常规操作.以下是最近项目中实践jqGrid的整理 1.引入到项目中来 jqG ...
- FZU 1627 Revival's road
矩阵快速幂. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inc ...
- Bullcow 牡牛和牝牛(bzoj 3398)
Description 约翰要带N(1≤N≤100000)只牛去参加集会里的展示活动,这些牛可以是牡牛,也可以是牝牛.牛们要站成一排.但是牡牛是好斗的,为了避免牡牛闹出乱子,约翰决定任意两只牡 ...
- 在 Sublime Text 3 中快捷打开 git-gui
在文件夹右键菜单上可以方便的打开 git-gui,在 st 里面也可以添加这个右键菜单. 步骤如下: 安装 SideBarEnhancements 插件. 在 SideBarEnhancements ...
- js 对象 视频 插入元素
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...