[HDU 5542] The Battle of Chibi
[题目链接]
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的更多相关文章
- hdu 5542 The Battle of Chibi(2015CCPC - C题)
题目链接:hdu 5542 首届CCPC的C题,比赛时一起搞了好久,最后是队友A出的,当时有试过用树状数组来优化 dp,然后今天下午也用树状数组搞了一下午,结果还是踩了和当时一样的坑:我总是把用来记录 ...
- 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 ...
- 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 ...
- 【树状数组+dp】HDU 5542 The Battle of Chibi
http://acm.hdu.edu.cn/showproblem.php?pid=5542 [题意] 给定长为n的序列,问有多少个长为m的严格上升子序列? [思路] dp[i][j]表示以a[i]结 ...
- HDOJ 5542 The Battle of Chibi
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题目大意:在n个数中找长度为m的单调上升子序列有多少种方案 题目思路:DP,离散化,树状数组优化 ...
- 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 ...
- CDOJ 1217 The Battle of Chibi
The Battle of Chibi Time Limit: 6000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
随机推荐
- .net web api跨域问题
No 'Access-Control-Allow-Origin' Ajax跨域访问解决方案 No 'Access-Control-Allow-Origin' header is present o ...
- 如何参加topcoder
1.注册账号 2.安装java运行环境 3.下载客户端 4.提示:应用程序已被java安全阻止:控制面板里找到java,将topcoder.com添加到安全列表 5.运行客户端
- javascript中异常处理案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 读书笔记7-浪潮之巅(part2)
浪潮之巅 ——成功的公司各有各的绝招,而失败的公司倒有不少的共同之处 奔腾的芯(Intel) 前身:在处理器性能还很平庸的年代,站在科技前沿的计算机公司都是集中在工作站级处理器领域的,而同IBM.DE ...
- SQL Server-聚焦过滤索引提高查询性能
前言 这一节我们还是继续讲讲索引知识,前面我们讲了聚集索引.非聚集索引以及覆盖索引等,在这其中还有一个过滤索引,通过索引过滤我们也能提高查询性能,简短的内容,深入的理解,Always to revie ...
- Axis2 1.7.4构建项目
1.下载axis2项目文件 http://axis.apache.org/axis2/java/core/download.html 2.Maven文件的pom.xml文件 3.将下载的axis2-1 ...
- rabbitmq基本原理(转载)
Rabbitmq基本原理(转载) MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端co ...
- BZOJ 1725: [Usaco2006 Nov]Corn Fields牧场的安排 状压动归
Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧 ...
- MySQL 单表查询多表查询
一 单表查询 表准备 create table emp( id int not null unique auto_increment, name varchar(20) not null, sex e ...
- Nginx1.14.2新增tcp/udp代理stream
[root@rhel nginx-1.12.1]# ./configure --help --help print this message --prefix=PATH set installatio ...