Cao Cao made up a big army and was going to invade the whole South China. Yu Zhou was worried about it. He thought the only way to beat Cao Cao is to have a spy in Cao Cao's army. But all generals and soldiers of Cao Cao were loyal, it's impossible to convince any of them to betray Cao Cao.

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 (树状数组+离散化)的更多相关文章

  1. 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 ...

  2. HDU 1394 树状数组+离散化求逆序数

    对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们 ...

  3. hdu 5792 树状数组+离散化+思维

    题目大意: Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a< ...

  4. [hdu 4417]树状数组+离散化+离线处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...

  5. hdu 4325 树状数组+离散化

    思路:这题的思路很容易想到,把所有时间点离散化,然后按时间一步一步来,当到达时间i的时候处理所有在i处的查询. 这个代码怎一个挫字了得 #include<iostream> #includ ...

  6. Disharmony Trees HDU - 3015 树状数组+离散化

    #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using ...

  7. Swaps and Inversions HDU - 6318 树状数组+离散化

    #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> us ...

  8. hdu 4638 树状数组 区间内连续区间的个数(尽可能长)

    Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  9. hdu 4777 树状数组+合数分解

    Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. JavaWeb之监听器

    1. 介绍         监听器是一个专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动.监听器其实就是一个实现特定接口的普通java程 ...

  2. 18 11 26 用多进程 多线程 携程 实现 http 服务器的创建

    下面是一个  多进程 服务器的创建 import socket import re import multiprocessing def service_client(new_socket): &qu ...

  3. SEO教程:快速增加360搜索引擎收录,360自动推送批量推送版

    上次改编了一下百度的JS推送代码,实现了批量推送 传送门>>>百度链接提交-js代码推送批量推送版 这次我们来研究360js自动推送代码. <script> (funct ...

  4. Python心得--新手开发注意

    1  注释 介绍 在大多数编程语言当中,注释都是一项非常有用的功能.我们开始编写的程序之中都只包含Python代码,但是随着程序越来越大.越来越复杂,就应在其中添加说明,对你解决问题的方法进行大致的阐 ...

  5. cmd定时自动弹窗命令

    at 17:00 /e:m,t,w,th,f,s,su msg * 弹窗文字

  6. MQTT--Paho C Client 的实现和详解

    概述  在文章Paho - MQTT C Cient的实现中,我介绍了如何使用Paho开源项目创建MQTTClient_pulish客户端.但只是简单的介绍了使用方法,而且客户端的结果与之前介绍的并不 ...

  7. JAVA初学者——算数运算符

    Hello!大家好,我是浩宇大熊猫,又是学习java的一天,开开森森~ 运算符:也就是对常量或者变量进行操作的符号 表达式:用运算符把常量或者变量连接起来符合java语法的式子就可以称为表达式,不同的 ...

  8. 微信小程序2048开发进度(二)

    对小程序首先进行游戏架构: 实现小程序的首页展示界面,初始化棋盘格,以及NEW GAME按钮,成绩展现.

  9. MySql索引机制

    第一部分 MySQL数据库索引的数据结构及算法理论 第二部分 MySQL索引实现机制 第三部分 MySQL中高性能使用索引的策略 数据结构及算法 MySQL官方对索引的定义为:索引(Index)是帮助 ...

  10. Pytorch——BERT 预训练模型及文本分类

    BERT 预训练模型及文本分类 介绍 如果你关注自然语言处理技术的发展,那你一定听说过 BERT,它的诞生对自然语言处理领域具有着里程碑式的意义.本次试验将介绍 BERT 的模型结构,以及将其应用于文 ...