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++ ...
随机推荐
- 6. IO复用:select 和 poll
select #include <sys/select.h> #include <sys/time.h> int select(int maxfdp1, fd_set *rea ...
- spring test---測试SpringMvc初识
如今越来越多人使用SpringMvc来开发系统,在开发中可定须要对后台url地址请求測试,而且返回预期的结果! Spring提供的測试类MockMvc来进行url地址请求測试,使用方方式: packa ...
- Jenkins+appium+testng持续集成
Create maven project in eclipseAdd Appium , Selenium dependancyAdd Test in TestNG testCreate TestNG ...
- 【bzoj2761】【JLOI2011】【不反复数字】【平衡树】
Description 给出N个数,要求把当中反复的去掉.仅仅保留第一次出现的数. 比如,给出的数为1 2 18 3 3 19 2 3 6 5 4.当中2和3有反复.去除后的结果为1 2 18 3 1 ...
- python 目录下的__init__.py
1 一个目录要成为一个package必须有__init__.py文件 The __init__.py files are required to make Python treat the direc ...
- Multitier architecture
Multitier architecture - Wikipedia https://en.wikipedia.org/wiki/Multitier_architecture Common layer ...
- filter、servlet、interceptor的执行顺序
1. Filter可认为是Servlet的一种“变种”,它主要用于对用户请求进行预处理,也可以对HttpServletResponse进行后处理,是个典型的处理链.它与Servlet的区别在于:它不能 ...
- unzip解压指定我文件夹
解压try.zip中指定的文件夹 unzip try.zip "try/*" shell中异常处理 { # your 'try' block executeCommandWhich ...
- scrollView 代理方法的实现顺序的些许区别
- [RK3288][Android6.0] 调试笔记 --- pmu(rk818)寄存器读写【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/76919134 Platform: Rockchip OS: Android 6.0 Kern ...