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. class选择器,外部样式表,选择器优先级

    class选择器: 先在相应标签中设置一个class属性,如class=“class名”.class名{ ……css样式}注:class名以英文字母开头,可以多个标签重复使用.优先级:标签名选择器 & ...

  2. 阿里云云服务器测试uwgis的基本流程

    基本背景 uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uwsg ...

  3. UML-什么是用例实现(场景实现)?

    1.总览图 解释: 用例--->领域模型 用例+领域模型--->设计模型(仅基于领域层的交互图) 2.什么是用例实现? 基于协作对象,如何在设计模型中实现某个用例.更确切的说是实现某个用例 ...

  4. Java多人聊天室第一版

    package cn.zhang.chat; import java.io.BufferedReader; import java.io.PrintWriter; /** * 所有用户均有的信息,单独 ...

  5. Spring源码解读:核心类DefaultListableBeanFactory的继承体系

    1 简介 我们常用的ClassPathXmlApplicationContext是AbstractRefreshableApplicationContext的子类,而DefaultListableBe ...

  6. git push报错! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://gitee.com/XXX.git

    git pull origin master --allow-unrelated-histories  //把远程仓库和本地同步,消除差异 git add . git commit -m"X ...

  7. 84.常用的返回QuerySet对象的方法使用详解:select_related, prefetch_related

    1.select_related: 只能用在一对多或者是一对一的关联模型之间,不能用在多对多或者是多对一的关联模型间,比如可以提前获取文章的作者,但是不能通过作者获取作者的文章,或者是通过某篇文章获取 ...

  8. 卡常的编译命令(含O2优化)

    不解释,直接来 //包括O2,O3之类的编译命令 //直接copy and paste #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma ...

  9. //使用PDO连接mysql数据库

    <?php //使用PDO连接mysql数据库 class pdo_con{     var $dsn = 'mysql:dbname=test; host:127.0.0.1';     va ...

  10. springboot +Thymeleaf+UEditor整合记录

    1,ueditor官网下载:https://ueditor.baidu.com/website/download.html  下载相应的工具包和源码,ps:源码放到工程中 2,解压放到放到项目中,sp ...