C. Subsequences
 
 

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.

Input
 

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.

Output
 

Print one integer — the answer to the problem.

Examples
input
 
5 2
1
2
3
5
4
output
7

题意:

  给你 一个 长度n 的数组 ,k,问你 长度k+1的子序列 有多少

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; #pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 1e5+, M = 5e5+, inf = 2e9, mod = ; int dp[N][];// 以i结尾 长度为j的方案数
/*
那么答案就是
dp[i][j] = dp[x][j-1] all a[x] < a[i] ;
*/
LL C[N][];
int n,k,a[N];
void update(int x,int k,LL c) {
for(int i = x; i < N; i += i&(-i)) {
C[i][k] += c;
}
}
LL query(int x,int k) {
LL s = ;
for(int i = x; i; i -= i&(-i)) {
s += C[i][k];
}
return s;
}
int main() {
scanf("%d%d",&n,&k);
for(int i = ; i <= n; ++i) scanf("%d",&a[i]);
update(a[],,);
for(int i = ; i <= n; ++i) {
update(a[i],,);
for(int j = ; j <= k; ++j) {
LL tmp = query(a[i]-,j);
update(a[i],j+,tmp);
}
}
LL ans = ;
printf("%I64d\n",query(n,k+));
return ;
}

  

Codeforces Testing Round #12 C. Subsequences 树状数组的更多相关文章

  1. Codeforces Testing Round #12 C. Subsequences 树状数组维护DP

    C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  2. Codeforces 597C. Subsequences (树状数组+dp)

    题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...

  3. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

  4. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  5. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  6. Codeforces - 828E DNA Evolution —— 很多棵树状数组

    题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ...

  7. Codeforces 570D TREE REQUESTS dfs序+树状数组 异或

    http://codeforces.com/problemset/problem/570/D Tree Requests time limit per test 2 seconds memory li ...

  8. Codeforces 786C Till I Collapse(树状数组+扫描线+倍增)

    [题目链接] http://codeforces.com/contest/786/problem/C [题目大意] 给出一个数列,问对于不同的k,将区间划分为几个, 每个区间出现不同元素个数不超过k时 ...

  9. Codeforces 216D Spider&#39;s Web 树状数组+模拟

    题目链接:http://codeforces.com/problemset/problem/216/D 题意: 对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色.否则为绿色, ...

随机推荐

  1. 【转】ArrayList其实就那么一回事儿之源码浅析

    转自:http://www.cnblogs.com/dongying/p/4013271.html?utm_source=tuicool&utm_medium=referral ArrayLi ...

  2. uniq 重复行统计

    uniq 命令   文字 uniq 是LINUX命令 用途 报告或删除文件中重复的行. 语法 uniq [ -c | -d | -u ] [ -f Fields ] [ -s Characters ] ...

  3. 一些笔试题(C/C++)

    1.there are two variables, don't use if.. else or ?: or switch or other judgement statements,find ou ...

  4. MySQL 利用SQL线程对Binlog操作

    背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...

  5. effective OC2.0 52阅读笔记(二 对象、消息、运行期)

    第二章:对象.消息.运行期 6 理解属性这一概念 总结:OC解决硬编码偏移量问题的做法,一种方案是把实例变量当做一种存储偏移量所用的特殊变量,交由类对象保管,偏移量会在运行期查找,叫做稳固的“应用程序 ...

  6. Java for LeetCode 209 Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  7. 关于js事件委托

    由于事件处理程序可以为现代 Web 应用程序提供交互能力,因此许多开发人员会不分青红皂白地 向页面中添加大量的处理程序. 在创建 GUI 的语言(如 C#)中,为 GUI 中的每个按钮添加一个 onc ...

  8. WebService到底是什?

    一.序言 大家或多或少都听过WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成分.但是不得不承认的是Web ...

  9. 【leetcode】Kth Largest Element in an Array (middle)☆

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  10. 调用c++接口类

    调用c++接口类 public class CarDeviceDll { /*对dll库进行一些初始化*/ [DllImport("IDI.dll")] public static ...