[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 ...
随机推荐
- logging (日志) 模块
本文源自景女神 函数式简单配置 import logging logging.debug('debug message') logging.info('info message') logging.w ...
- Tomcat 报错 记录
Resource is out of sync with the file system: 该错误为替换了image中的图片而没有进行更新,造成找不到该资源,进而保存,解决只要eclipse刷新一下F ...
- JavaScript的并且&&
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...
- 三维重建:QT+OpenNI+Kinect图像校正
后记: 当时能不放弃这个方向是因为这里面涉及了一种很有效的三位场景存储方式,可能给出除图元建模之外的一种三维场景描述方式.这和Flash与位图的对比一样,基于图元的flash始终抵不过基于点描述的位图 ...
- spring之interceptor篇
springmvc中要写一个拦截器非常的简单,有两种方式:要么实现HandlerInterceptor接口或者继承实现了该接口的类,如spring已经为我们写好的一个HandlerIntercepto ...
- 将电脑特定文件夹保存在U盘中
为什么 各种网盘,借着国家扫黄的阶梯,纷纷取消自己的网盘的服务.但自己有一些不是很大,但又很重要的东西,比如说代码(虽然学的渣) 怎么做 再网上百度,有一些将U盘的文件偷偷拷到电脑的脚本,改一下复制文 ...
- Juery实现选项卡
选项卡是一种很常用的组件.比如3个选项的选项卡,比较笨的一种办法是,把3个状态写成3个独立页面,互相链接.这样做的问题也显而易见,切换的时候url会变.如果是手机端网页,加载慢一点,给人的感觉是不断的 ...
- nyoj28-大数阶乘
大数阶乘 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数m(0& ...
- BZOJ 2333 [SCOI2011]棘手的操作 (可并堆)
码农题.. 很显然除了两个全局操作都能用可并堆完成 全局最大值用个multiset记录,每次合并时搞一搞就行了 注意使用multiset删除元素时 如果直接delete一个值,会把和这个值相同的所有元 ...
- C#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值
IntPtr cbh= new IntPtr(handle); //ComboBox的句柄 SendMessage(cbh, 0x014D, new IntPtr(-1), "需要选中的下拉 ...