[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 ...
随机推荐
- 浅析CLR的事件
文章目录: 1.C#(.net framework框架)中的事件以及特点 2.事件的组成部分 3.编辑器如何实现事件的 4.显式实现事件 1.C#(.net framework ...
- Svn install and use
1.安装服务 使用yum安装subversion,简单.不繁琐. 1 yum install -y subversion 2.创建版本库 1 2 mkidr /svn/obj ...
- 使用Micrisoft.net设计方案 第一章 企业解决方案中构建设计模式
第一章企业解决方案中构建设计模式 我们知道的系统总是由简单到复杂,而不是直接去设计一个复杂系统.如果直接去设计一个复杂系统,结果最终会导致失败.在设计系统的时候,先设计一个能够正常工作的系统,然后在此 ...
- (转)50 个 jQuery 小技巧
1. 如何修改jQuery默认编码(例如默认UTF-8改成改GB2312): $.ajaxSetup({ajaxSettings:{ contentType:"application/x-w ...
- nodejs supervisor安装
使用supervisor提高nodejs调试效率 用超级用户运行npm -g install supervisor命令,说是顺 >$ sudo npm -g install supervisor ...
- solr 4.8+mysql数据库数据导入 + mmseg4j中文全文索引 配置笔记
转载请标明出处:http://www.cnblogs.com/chlde/p/3768733.html 1.如何将solr部署,请参考之前的文章 2.按上述配置好后,在solr_home文件夹中,将包 ...
- Shiro从数据表中初始化资源和权限
之前在测试的Web工程下,我们在applicationContext.xml中配置了shiroFilter资源拦截器信息: <bean id="shiroFilter" cl ...
- trigger事件就是继承某一个类的事件.
<html><head><script type="text/javascript" src="/jquery/jquery.js" ...
- WPF 利用RichTextBox 打印出不同颜色的文本
using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows ...
- 洛谷P1486 [NOI2004]郁闷的出纳员
Code: #include<cstdio> #include<algorithm> using namespace std; struct Node{ int s,val,t ...