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 ...
随机推荐
- 《Thinking in Java》位运算
按位操作符: 首先先记住一件事,方便理解:是否对应正负对应10. 1.与(&):11得1,10得0,00得0. 2.或(|):11得1,10得1,00得0. 3.异或(^):11得0,10得1 ...
- Linux环境创建交换分区
最近在准备在移动端跑一下深度学习训练好的模型,在RK3399的板子上安装scipy时报错.网上查了一下,由于内存不足导致,做个交换分区就搞定了.那么如何做交换分区呢.话不多说,直接开撸. ------ ...
- Class.forName(String className)解析
功能: Class.forName(xxx.xx.xx)返回的是一个类 Class.forName(xxx.xx.xx)的作用是要求JVM查找并加载指定的类, 也就是说JVM会执行该类的静态代码段 一 ...
- JavaWeb乱码问题及统一全站编码(通过Filter实现)
1. public class CharacterFilter implements Filter { private String characterEncoding = null; FilterC ...
- potplayer记住播放进度
(右键——选项)F5——播放——记忆视频播放位置
- ssh首次链接出现yes/no提示和ansible提示
修改文件: /etc/ssh/ssh_config 在文件中添加如下信息:StrictHostKeyChecking no 改本机的/etc/ssh/ssh_config文件中的"# Str ...
- Java 面向对象 异常处理:RunTimeexception,try-catch,异常声明throws,自定义异常,throw和throws的区别,多异常处理(9)
Java 面向对象 异常处理:RunTimeexception,try-catch,异常声明throws,自定义异常,throw和throws的区别,多异常处理(9)
- 系统学习python第六天学习笔记
1.补充 1.列表方法补充 reverse,反转. v1 = [1,2,3111,32,13] print(v1) v1.reverse() print(v1) sort,排序 v1 = [11,22 ...
- GNU Autotool介绍
参考文档: automake(GNU教程) 几句话说清楚17:用Makefile.am和configure.ac构建一个专业的Hello World Creatingamhello-1.0.tar.g ...
- javascript中的location的用法
javascript中的location.href有很多种用法,主要如下. self.location.href="/url" 当前页面打开URL页面 location.href= ...