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 ...
随机推荐
- ngrok内网穿透神器
ngrok类似国内的花生壳,可以将本地的内网映射到公网上,这样就可以做web开发,微信开发了.下面就介绍下ngrok是怎么配置的吧. 方式一: 一.打开ngrok的官网https://ngrok.co ...
- mx51 IPU 透明处理
Freescale MX51平台的透明处理根据bpp(bits_per_pixel)不同,处理方式有所不同. 透明处理涉及到两个图层的合并,这个合并操作是MX51 IPU的DP(Display pro ...
- child_process小解
js是一种单进程单线程的语言,但现行的cpu都是多核的,为了解决单进程单线程对多核使用不足的问题,child_process应运而生,理想情况下每个进程各自利用一个内核. 主要有四种方法来创建子进程, ...
- 针对ie9写特殊的样式
<!--ie9样式重置--> <!--[if IE 9]> <style> select { background: none; padding-right: 0 ...
- Linux修改SSH端口和禁止Root远程登陆
Linux修改ssh端口22 vi /etc/ssh/ssh_config vi /etc/ssh/sshd_config 然后修改为port 8888 以root身份service sshd res ...
- VHDL设计问题
在做算术运算的时候,不可以用std_ulogic_vector,必须是std_logic_vector.
- C primer plus 第五版十二章习题
看完C prime plus(第五版)第十二章,随带完成了后面的习题. 1.不使用全局变量,重写程序清单12.4的程序. 先贴出12.4的程序,方便对照: /* global.c --- 使用外部变量 ...
- Android 关于 OnScrollListener 事件顺序次数的简要分析
在 Android 的 OnScrollListener 整个事件我主要分析下他的执行顺序: 实现滚动事件的监听接口 new AbsListView.OnScrollListener(){ @Over ...
- magento删除数据
1.删除一条数据: $delete = Mage::getSingleton("core/resource")->getConnection("core_wr ...
- flask部署 supervisor的使用
安装supervisor sudo apt-get install supervsor 配置 打开 /etc/supervisor/supervisor.conf 可以看到 同目录文件夹下的 co ...