[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 ...
随机推荐
- selenium 最大化浏览器是解决浏览器和驱动不匹配的方法如下
那么要想selenium成功的操作chrome浏览器需要经历如下步骤: 1.下载ChromeDriver驱动包(下载地址: http://chromedriver.storage.googleapis ...
- Solr.NET快速入门(五)【聚合统计,分组查询】
聚合统计 属性 说明 Min 最小值 Max 最大值 Sum 总和 Count 记录数,也就是多少行记录 Missing 结果集中,有多少条记录是空值 SumOfSquares 平方和(x1^2 + ...
- cropper+pillow处理上传图片剪裁(二)
上次说到处理上传头像的方法是临时保存在本地,其实这样做并不妥,而且修改后的头像重新上传到model中也很麻烦,差了很多资料,解决了这个问题 大致思路:用户上传原图和修改数据—PIL修改后将图片保存为内 ...
- BZOJ1211: [HNOI2004]树的计数(prufer序列)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2987 Solved: 1111[Submit][Status][Discuss] Descript ...
- 最简单的一致性Hash算法实现
import java.util.Collection;import java.util.SortedMap;import java.util.TreeMap; public class Consis ...
- main函数解析
原文链接:http://parisliu2008.blog.163.com/blog/static/95070867200951510412959/ main参数 2009-06-15 10:41:2 ...
- 路飞学城Python-Day180
部署作业 [pythonanywhere]
- 谈谈python里面关于任务队列
谈谈python里面关于任务队列 为什么要做任务队列 要回答这个问题我们首先看看在流水线上的案列,如果人的速度很慢,机器的速度比人的速度快很多,就会造成,机器生产的东西没有及时处理,越积越多,造成阻塞 ...
- Linux 文件压缩
压缩工具 compress/uncompress:对应 .Z 结尾的压缩格式文件 压缩格式:gz.bz2.xz.zip.Z gzip 压缩文件并删除源文件(生成.gz的文件) gunzip 解 ...
- hdu 1556 线段树区间延迟更新好题
656mS #include<stdio.h> #include<stdlib.h> #define N 110000 struct node { int x,y,yanchi ...