C - The Battle of Chibi HDU - 5542 (树状数组+离散化)
So there is only one way left for Yu Zhou, send someone to fake surrender Cao Cao. Gai Huang was selected for this important mission. However, Cao Cao was not easy to believe others, so Gai Huang must leak some important information to Cao Cao before surrendering.
Yu Zhou discussed with Gai Huang and worked out NN information to be leaked, in happening order. Each of the information was estimated to has aiai value in Cao Cao's opinion.
Actually, if you leak information with strict increasing value could accelerate making Cao Cao believe you. So Gai Huang decided to leak exact MM information with strict increasing value in happening order. In other words, Gai Huang will not change the order of the NN information and just select MM of them. Find out how many ways Gai Huang could do this.
InputThe first line of the input gives the number of test cases, T(1≤100)T(1≤100). TT test cases follow.
Each test case begins with two numbers N(1≤N≤103)N(1≤N≤103) and M(1≤M≤N)M(1≤M≤N), indicating the number of information and number of information Gai Huang will select. Then NN numbers in a line, the ithithnumber ai(1≤ai≤109)ai(1≤ai≤109) indicates the value in Cao Cao's opinion of the ithith information in happening order.OutputFor each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the ways Gai Huang can select the information.
The result is too large, and you need to output the result mod by 1000000007(109+7)1000000007(109+7).Sample Input
2
3 2
1 2 3
3 2
3 2 1
Sample Output
Case #1: 3
Case #2: 0
Hint
In the first cases, Gai Huang need to leak 2 information out of 3. He could leak any 2 information as all the information value are in increasing order.
In the second cases, Gai Huang has no choice as selecting any 2 information is not in increasing order.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
const int mod=1e9+;
int a[maxn],lsh[maxn];
int n,m;
int dp[][];
int lowbit(int x)
{
return x&-x;
}
void add(int x,int y,ll val)
{
for(int i=x;i<=n;i+=lowbit(i)){
dp[i][y]=(dp[i][y]+val)%mod;
}
}
int sum(int x,int y)
{
int ans=;
for(int i=x;i>=;i-=lowbit(i)){
ans=(ans+dp[i][y])%mod;
}
return ans;
}
int main()
{
ios::sync_with_stdio();
int T,k=;
cin>>T;
while(T--){
memset(dp,,sizeof(dp));
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>a[i];
lsh[i]=a[i];
}
sort(lsh+,lsh++n);
// int len=unique(lsh+1,lsh+1+n)-lsh-1;//去不去重都一样啦,下面是lowerbound
for(int i=;i<=n;i++){
int x=lower_bound(lsh+,lsh++n,a[i])-lsh;
add(x,,);
for(int j=;j<=m;j++){
add(x,j,sum(x-,j-));
}
}
cout<<"Case #"<<k++<<": ";
cout<<sum(n,m)<<endl;
}
return ;
}
C - The Battle of Chibi HDU - 5542 (树状数组+离散化)的更多相关文章
- 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 1394 树状数组+离散化求逆序数
对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们 ...
- hdu 5792 树状数组+离散化+思维
题目大意: Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a< ...
- [hdu 4417]树状数组+离散化+离线处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...
- hdu 4325 树状数组+离散化
思路:这题的思路很容易想到,把所有时间点离散化,然后按时间一步一步来,当到达时间i的时候处理所有在i处的查询. 这个代码怎一个挫字了得 #include<iostream> #includ ...
- Disharmony Trees HDU - 3015 树状数组+离散化
#include<cstdio> #include<cstring> #include<algorithm> #define ll long long using ...
- Swaps and Inversions HDU - 6318 树状数组+离散化
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> us ...
- hdu 4638 树状数组 区间内连续区间的个数(尽可能长)
Group Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 4777 树状数组+合数分解
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- SAP_FICO常用事务代码
1.会计科目维护: FS00:总账科目主记录维护 FSP0:科目表中总账科目主记录维护 FSS0:公司代码中总账科目主记录维护 2.会计凭证创建 FB01:创建凭证 F-02:总账凭证创建(在FB01 ...
- Runtime之方法交换
在没有一个类的实现源码的情况下,想改变其中一个方法的实现,除了继承它重写.和借助类别重名方法暴力抢先之外,还有就是方法交换 方法交换的原理:在OC中调用一个方法其实是向一个对象发送消息,查找消息的唯一 ...
- Java中的合并与重组(下)
通过优锐课核心java学习笔记中,我们可以看到,码了很多专业的相关知识, 分享给大家参考学习. Java中的合并与重组上部分链接:https://www.cnblogs.com/youruike1/p ...
- (转)ERROR : The processing instruction target matching "[xX][mM][lL]" is not allowed.
现象:ERROR : The processing instruction target matching "[xX][mM][lL]" is not allowed. 异常解 ...
- 【转帖】虚拟化Pod性能比裸机还要好,原因竟然是这样!
虚拟化Pod性能比裸机还要好,原因竟然是这样! http://www.itpub.net/2020/02/27/5340/ 其实感觉 linux也可以做到 NUMA的节点优化 其实 直接在 ESXi上 ...
- 特斯拉私有化VS蔚来上市,电动汽车站在十字路口上
当下,对于电动汽车来说既是一个最好的时代,也是一个最坏的时代.好的一面是业界.投资者.消费者对电动汽车的关注度愈来愈高,坏的一面则是电动汽车正处于一个非常尴尬的处境.从大环境来看,电动汽车自身的产品力 ...
- 18 11 07 pygame 继续使用
---恢复内容开始--- 1 给原来的游戏不定时 增加一些敌机 用到了pygame的定时器 定时器就是每隔一段时间 就进行一次相同的操作 2 pyagame 在捕获键盘操作有两种 1 ...
- 约数个数函数(d)的一个性质证明
洛谷P3327 [SDOI2015]约数个数和 洛谷P4619 [SDOI2018]旧试题 要用到这个性质,而且网上几乎没有能看的证明,所以特别提出来整理一下. \[ d(AB) = \sum_{x| ...
- 201609-1 最大波动 Java
用绝对值,后一天减去前一天即可 import java.util.Scanner; public class Main { public static void main(String[] args) ...
- 年近30的Java程序员为了达到月入三万的目标,都做了哪些准备?
1.我觉得像我这般年纪的(29岁),有相对扎实技术功底的(就不自谦了),对赚钱有着强烈欲望的程序员,应该定一个切实的小目标——五年内月入三万! 之所以要定这个目标,最主要的原因是老婆的批评刺痛了我—— ...