[题目链接]

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的更多相关文章

  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. SSRS 报表 如何加参数

    SSRS 报表 如何加参数 连接上以后出现一个问题 就是给报表加上参数以后报表不断刷新,跟上次那个报表刷新是同样的问题.那么下面我们来解决一下. 1. 这是给报表添加默认参数进入页面后就不断的刷新刷新 ...

  2. ajax获取跨域数据

    1.效果图 2.源码 <%@ page contentType="text/html;charset=UTF-8" language="java" %&g ...

  3. 使用Scanner获取键盘输入 (转)

    原文地址:https://www.cnblogs.com/SzBlog/p/5404335.html 后面有改动 使用Scanner类可以很方便地便获取用户的键盘输入,Scanner是一个基于正则表达 ...

  4. 【Oracle】SCOPE=MEMORY|SPFILE|BOTH

    SCOPE=MEMORY|SPFILE|BOTH 指示了修改参数时的“作用域”: SCOPE=MEMORY :只在实例中修改,重启数据库后此次修改失效. SCOPE=SPFILE :只修改SPFILE ...

  5. UWP App Services in Windows 10

    1.AppServices in Universal Windows Platform(UWP) UWP 应用服务可以提供给另一个UWP应用.在Win10系统中,一个应用服务当作应用的一个方法和机制来 ...

  6. STL:使用string、vector、complex和limits

    (有少量修改!)使用到了STL的算法库: #include<algorithm> #include<vector> //属于STL库 模板库 写库的人为了和标准C和C++库区分 ...

  7. 杭电 2035 人见人爱A^B【同余】

    #include<stdio.h> int main() { int a,b; int s; int i; while(scanf("%d %d",&a,&am ...

  8. js 按钮连击 减少触发事件次数

    <body> <input type="button" onClick="testbtn()" value="测试按钮"& ...

  9. Django01 web http 基础

    一.内容回顾 1.python基础 2.网络编程 3.并发编程 4.前端 5.数据库(MySQL) 二.今日概要 1.了解Web应用程序的本质 2.Django简介及安装使用 三.今日详细 1.最简单 ...

  10. 【leecode】独特的电子邮件地址

    每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...