[题目链接]

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

[算法]

树状数组优化DP

[代码]

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define MAXN 1010
  4. const int P = 1e9 + ;
  5.  
  6. int i,j,T,TC,n,m,len,ans;
  7. int a[MAXN],tmp[MAXN],rk[MAXN];
  8. int f[MAXN][MAXN];
  9.  
  10. class BinaryIndexedTree
  11. {
  12. private :
  13. int c[MAXN];
  14. public :
  15. inline int lowbit(int x)
  16. {
  17. return x & (-x);
  18. }
  19. inline void clear()
  20. {
  21. memset(c,,sizeof(c));
  22. }
  23. inline void modify(int pos,int val)
  24. {
  25. int i;
  26. for (i = pos; i <= len; i += lowbit(i)) c[i] =(c[i] + val) % P;
  27. }
  28. inline int query(int pos)
  29. {
  30. int i;
  31. int ret = ;
  32. for (i = pos; i; i -= lowbit(i)) ret = (ret + c[i]) % P;
  33. return ret;
  34. }
  35. } BIT;
  36.  
  37. int main()
  38. {
  39.  
  40. scanf("%d",&T);
  41. while (T--)
  42. {
  43. scanf("%d%d",&n,&m);
  44. for (i = ; i <= n; i++)
  45. {
  46. scanf("%d",&a[i]);
  47. tmp[i] = a[i];
  48. }
  49. sort(tmp+,tmp+n+);
  50. len = unique(tmp+,tmp+n+) - tmp - ;
  51. for (i = ; i <= n; i++) rk[i] = lower_bound(tmp+,tmp+len+,a[i]) - tmp;
  52. for (i = ; i <= n; i++) f[][i] = ;
  53. for (i = ; i <= m; i++)
  54. {
  55. BIT.clear();
  56. for (j = ; j <= n; j++)
  57. {
  58. f[i][j] = BIT.query(rk[j] - );
  59. BIT.modify(rk[j],f[i-][j]);
  60. }
  61. }
  62. ans = ;
  63. for (i = ; i <= n; i++) ans = (ans + f[m][i]) % P;
  64. printf("Case #%d: %d\n",++TC,ans);
  65. }
  66.  
  67. return ;
  68. }

[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. logging (日志) 模块

    本文源自景女神 函数式简单配置 import logging logging.debug('debug message') logging.info('info message') logging.w ...

  2. Tomcat 报错 记录

    Resource is out of sync with the file system: 该错误为替换了image中的图片而没有进行更新,造成找不到该资源,进而保存,解决只要eclipse刷新一下F ...

  3. JavaScript的并且&&

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  4. 三维重建:QT+OpenNI+Kinect图像校正

    后记: 当时能不放弃这个方向是因为这里面涉及了一种很有效的三位场景存储方式,可能给出除图元建模之外的一种三维场景描述方式.这和Flash与位图的对比一样,基于图元的flash始终抵不过基于点描述的位图 ...

  5. spring之interceptor篇

    springmvc中要写一个拦截器非常的简单,有两种方式:要么实现HandlerInterceptor接口或者继承实现了该接口的类,如spring已经为我们写好的一个HandlerIntercepto ...

  6. 将电脑特定文件夹保存在U盘中

    为什么 各种网盘,借着国家扫黄的阶梯,纷纷取消自己的网盘的服务.但自己有一些不是很大,但又很重要的东西,比如说代码(虽然学的渣) 怎么做 再网上百度,有一些将U盘的文件偷偷拷到电脑的脚本,改一下复制文 ...

  7. Juery实现选项卡

    选项卡是一种很常用的组件.比如3个选项的选项卡,比较笨的一种办法是,把3个状态写成3个独立页面,互相链接.这样做的问题也显而易见,切换的时候url会变.如果是手机端网页,加载慢一点,给人的感觉是不断的 ...

  8. nyoj28-大数阶乘

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数m(0& ...

  9. BZOJ 2333 [SCOI2011]棘手的操作 (可并堆)

    码农题.. 很显然除了两个全局操作都能用可并堆完成 全局最大值用个multiset记录,每次合并时搞一搞就行了 注意使用multiset删除元素时 如果直接delete一个值,会把和这个值相同的所有元 ...

  10. C#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值

    IntPtr cbh= new IntPtr(handle); //ComboBox的句柄 SendMessage(cbh, 0x014D, new IntPtr(-1), "需要选中的下拉 ...