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++ ...
随机推荐
- [Android]Android5.0实现静默接听电话功能
原因: android曾经能够通过AIDL进行静默接听.可是5.0以后就被谷歌给屏蔽了.这时候我们仅仅能通过其它方式实现了. 解决方式: try { Runtime.getRuntime().exec ...
- HDU 5188 背包
有N道题.要求得到最少W分 给出N道题的:每道题用时T.分数V,应在且必须在L时刻提交才干得分 问得到W分所用的最少的时间 以L-T排序,然后做01背包就可以 #include "stdio ...
- java面试题(摘录)
1.抽象,继承,封装,多态 2.基本数据类型的字节数 byte:1.int:4.char:2.long:8.float:4.double:8.boolean:1 和short:2 3.String , ...
- apache benchmark
1 ab是什么 是一个web高并发测试工具,可以发送get.put.post请求. 2 ab -n和-c共存 -c是concurrency的缩写,即同一时间发送多个请求. -n是指本次总共发送多少个请 ...
- Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland
D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...
- (C\C++)inline关键字
背景(C&C++中) inline关键字用来定义一个类的内联函数,引入它的主要原因是用它替代C中表达式形式的宏定义. 表达式形式的宏定义如: #define ExpressionName(Va ...
- 织梦CMS使用JS实时动态调用评论数
网站中只要启用了会员系统,网站中的文章就会有评论,在网站首页中调用会员评论也能提升会员体验度,网页都是静态页面,如果每有一个评论都更新html的话就会有点浪费资源了,所以这里给大家分享一个使用JS调用 ...
- Oracle: 禁忌给一般用户授权create any procedure、execute any procedure
给一般用户授 create any procedure.execture any procedure 这2个权限是很不安全的事. 因为授权后,通过一些处理,该用户可以取得dba权限,请一定注意. 下面 ...
- 管理 Word 博客账户
1.1 多个博客账户 笔者的电脑上,Word 2013 有多个博客账户,如下图所示: 图1.1 多个博客账户 这些账户的名称在 Word 里是自动生成的,无法更改.账户一多就无法与相应的网站一一对应, ...
- SPOJ:Stack Overflow(并查集)
Stack is a basic data structure. Where 3 operation can be done- Push: You can push object to the sta ...