[题目链接]

http://acm.hdu.edu.cn/showproblem.php?pid=5542

[算法]

树状数组优化DP

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 1010
const int P = 1e9 + ; int i,j,T,TC,n,m,len,ans;
int a[MAXN],tmp[MAXN],rk[MAXN];
int f[MAXN][MAXN]; class BinaryIndexedTree
{
private :
int c[MAXN];
public :
inline int lowbit(int x)
{
return x & (-x);
}
inline void clear()
{
memset(c,,sizeof(c));
}
inline void modify(int pos,int val)
{
int i;
for (i = pos; i <= len; i += lowbit(i)) c[i] =(c[i] + val) % P;
}
inline int query(int pos)
{
int i;
int ret = ;
for (i = pos; i; i -= lowbit(i)) ret = (ret + c[i]) % P;
return ret;
}
} BIT; int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d%d",&n,&m);
for (i = ; i <= n; i++)
{
scanf("%d",&a[i]);
tmp[i] = a[i];
}
sort(tmp+,tmp+n+);
len = unique(tmp+,tmp+n+) - tmp - ;
for (i = ; i <= n; i++) rk[i] = lower_bound(tmp+,tmp+len+,a[i]) - tmp;
for (i = ; i <= n; i++) f[][i] = ;
for (i = ; i <= m; i++)
{
BIT.clear();
for (j = ; j <= n; j++)
{
f[i][j] = BIT.query(rk[j] - );
BIT.modify(rk[j],f[i-][j]);
}
}
ans = ;
for (i = ; i <= n; i++) ans = (ans + f[m][i]) % P;
printf("Case #%d: %d\n",++TC,ans);
} return ;
}

[HDU 5542] The Battle of Chibi的更多相关文章

  1. hdu 5542 The Battle of Chibi(2015CCPC - C题)

    题目链接:hdu 5542 首届CCPC的C题,比赛时一起搞了好久,最后是队友A出的,当时有试过用树状数组来优化 dp,然后今天下午也用树状数组搞了一下午,结果还是踩了和当时一样的坑:我总是把用来记录 ...

  2. 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 ...

  3. HDU 5542 - The Battle of Chibi - [离散化+树状数组优化DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5542 Problem DescriptionCao Cao made up a big army an ...

  4. 【树状数组+dp】HDU 5542 The Battle of Chibi

    http://acm.hdu.edu.cn/showproblem.php?pid=5542 [题意] 给定长为n的序列,问有多少个长为m的严格上升子序列? [思路] dp[i][j]表示以a[i]结 ...

  5. HDOJ 5542 The Battle of Chibi

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题目大意:在n个数中找长度为m的单调上升子序列有多少种方案 题目思路:DP,离散化,树状数组优化 ...

  6. 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 ...

  7. 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 ...

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

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

  9. CDOJ 1217 The Battle of Chibi

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

随机推荐

  1. Spring DATA MongoDB @DBref查询,or和and联合查询

    @DBref文档关联,在按该类型查询的时候,在字段名后加上关联表的字段名即可,如: Criteria.where("bloggroup.$id"), $id代表关联表的oid字段. ...

  2. Java数组的运用

    Java数组 应用1: 大乐透彩票模拟器: 规则: 前区01-35中随机生成5个号码 后区01-12中随机生成2个号码 模拟操作,系统自动生成号码组合,并且按从小到大的顺序输出结果 同时要求可以选择生 ...

  3. Python Tutorial笔记

    Python Tutorial笔记 Python入门指南 中文版及官方英文链接: Python入门指南 (3.5.2) http://www.pythondoc.com/pythontutorial3 ...

  4. RabbitMQ学习之集群镜像模式配置

    1.增加负载均衡器 关于负载均衡器,商业的比如F5的BIG-IP,Radware的AppDirector,是硬件架构的产品,可以实现很高的处理能力.但这些产品昂贵的价格会让人止步,所以我们还有软件负载 ...

  5. Rx (Reactive Extensions)

    The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using ...

  6. 优动漫PAINT如何打开图形文件

    优动漫PAINT也就是我们常说的clip studio paint(CSP)的中文版本,在优动漫PAINT软件中打开文件的方式有很多,您可以直接拖拽至优动漫PAINT界面或者文档窗口,也可以执行文件菜 ...

  7. 认识优动漫PAINT,优动漫PAINT基本功能有哪些?

    优动漫PAINT是一款搭载了绘制漫画.插画所需所有功能的软件.拥有笔感自然真实.表现形式多样的画笔工具,及高效.完美.便捷的上色工具等. 本文将通过由优动漫PAINT描绘的作品为例,简单介绍该软件的功 ...

  8. 超实用的JavaScript代码段

    1. 判断日期是否有效 JavaScript中自带的日期函数还是太过简单,很难满足真实项目中对不同日期格式进行解析和判断的需要.JQuery也有一些第三方库来使日期相关的处理变得简单,但有时你可能只需 ...

  9. hibernate详细配置

    映射配置 <!-- 映射文件: 映射一个实体类对象:  描述一个对象最终实现可以直接保存对象数据到数据库中.  --> <!-- package: 要映射的对象所在的包(可选,如果不 ...

  10. Zabbix系列-REHL6.10离线方式安装Zabbix 4.0 LTS

    环境 第零步:关闭系统默认防火墙 setenforce 0 sed -i -r "/^SELINUX=/c SELINUX=disabled" /etc/selinux/confi ...