Testing Round #12 C
Description
For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Print one integer — the answer to the problem.
- 5 2
1
2
3
5
4
- 7
题意:求长度为k+1的上升子序列有多少个
解法:sum=dp[0][k+1]+dp[1][k+1]+dp[2][k+1]+....dp[n][k+1]
dp[x][y]是x为上升子序列最后一个元素,长度为y的个数
用树状数组维护,更新的是num为上升子序列最后一个元素,长度为j时,加上num为上升子序列最后一个元素,长度为j-1时个数
最后求sum(n,m+1)总和
- #include <bits/stdc++.h> .h>
- using namespace std;
- #define ll long long
- ll n,m;
- ll dp[][];
- ll bit(ll x)
- {
- return x&(-x);
- }
- void up(ll x,ll y,ll ans)
- {
- while(x<)
- {
- dp[x][y]+=ans;
- x+=bit(x);
- }
- }
- ll sum(ll x,ll y)
- {
- ll ans=;
- while(x>)
- {
- ans+=dp[x][y];
- x-=bit(x);
- }
- return ans;
- }
- int main()
- {
- cin>>n>>m;
- up(,,);
- for(int i=;i<=n;i++)
- {
- ll num;
- cin>>num;
- for(int j=m+;j>=;j--)
- {
- up(num,j,sum(num,j-));
- }
- }
- cout<<sum(n,m+)<<endl;
- return ;
- }
Testing Round #12 C的更多相关文章
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- Testing Round #12 A
A. Divisibility time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp
题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...
- Testing Round #12 B
Description A restaurant received n orders for the rental. Each rental order reserve the restaurant ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...
随机推荐
- gcc编译minigui新程序报错
!ggcc *.c -ljpeg -lpng -lminigui -lpthread/usr/local/lib/libminigui.so: undefined reference to `dl ...
- hibernate工作原理及作用
转载自 http://www.cnblogs.com/dashi/p/3597969.html#commentform JAVA Hibernate工作原理及为什么要用 hibernate 简介:hi ...
- Kafka知识点汇总
整体结构 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZXJpY19zdW5haA==/font/5a6L5L2T/fontsize/400/fill/I ...
- 杭电 1596 find the safest road (最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 这道题目与杭电2544最短路的思想是一样的.仅仅只是是把+改成了*,输入输出有些不一样而已. find t ...
- 三分钟教你学Git(十四) 之 线下传输仓库
有时候还有一个人不能从远程直接clone仓库或者说由于非常大,clone非常慢或其他原因.我们能够使用bundle命令将Git仓库打包,然后通过U盘或者是其他介质拷贝给他,这样他拿到打包好的仓库后能够 ...
- bash shell最基本的语法
1 shell语句的基本构成 shell每个基本的构成元素之间都相隔一个空格. 比如[ -e file ],[.-e.file.]这四个基本元素之间都相隔了一个空格. 同样的道理[ ! -e file ...
- Android Studio解决导入项目非常慢
Android Studio比Eclipse ADT有巨大的优势.Android Studio原生支持使用Gradle来构建项目,使用动态语言Groovy定义项目构建的过程,避免了build.xml文 ...
- luogu3373 【模板】线段树2
题目大意: 已知一个数列,你需要进行下面三种操作:1.将某区间每一个数乘上x2.将某区间每一个数加上x3.求出某区间每一个数的和 本线段树的标记是个二元组:add和mul,其代表将一个线段中的每一个点 ...
- 【Selenium】测试流程和框架
流程: 分析自动化测试需求→制定自动化测试计划→设计自动化测试用例→搭建环境→编写脚本→分析结果→维护脚本 框架: 线性测试.模块化测试.数据驱动.关键字驱动
- HihoCoder1084: 扩展KMP(二分+hash,求T串中S串的数量,可以失配一定次数)
时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 你知道KMP吗?它是用于判断一个字符串是否是另一个字符串的子串的算法.今天我们想去扩展它. 在信息理论中,在两个相同长度的字 ...