C. Subsequences

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/597/problem/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.

⋅2. Ignoring the buoys and relying on dogfighting to get point. If you and your opponent meet in the same position, you can try to fight with your opponent to score one point. For the proposal of game balance, two players are not allowed to fight before buoy #2 is touched by anybody.

There are three types of players.

Speeder:
As a player specializing in high speed movement, he/she tries to avoid
dogfighting while attempting to gain points by touching buoys.
Fighter:
As a player specializing in dogfighting, he/she always tries to fight
with the opponent to score points. Since a fighter is slower than a
speeder, it's difficult for him/her to score points by touching buoys
when the opponent is a speeder.
All-Rounder: A balanced player between Fighter and Speeder.

There will be a training match between Asuka (All-Rounder) and Shion (Speeder).
Since the match is only a training match, the rules are simplified: the game will end after the buoy #1 is touched by anybody. Shion is a speed lover, and his strategy is very simple: touch buoy #2,#3,#4,#1 along the shortest path.

Asuka is good at dogfighting, so she will always score one point by dogfighting with Shion, and the opponent will be stunned for T seconds after dogfighting.
Since Asuka is slower than Shion, she decides to fight with Shion for
only one time during the match. It is also assumed that if Asuka and
Shion touch the buoy in the same time, the point will be given to Asuka
and Asuka could also fight with Shion at the buoy. We assume that in
such scenario, the dogfighting must happen after the buoy is touched by
Asuka or Shion.

The speed of Asuka is V1 m/s. The speed of Shion is V2 m/s. Is there any possibility for Asuka to win the match (to have higher score)?

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.

Sample Input

5 2
1
2
3
5
4

Sample Output

7

HINT

题意

给你n个数,然后问你长度为k的上升子序列有多少个

题解:

dp[i][j]表示以大小为i结尾,长度为j的上升子序列的个数

然后我们转移就用前面小于a[i]的dp[k][j-1]的和转移过来就好了

代码

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
#define maxn 100105
long long dp[maxn][];
void add(int x,int y,long long val)
{
for(int i=x;i<maxn;i+=i&(-i))
dp[i][y]+=val;
}
long long sum(int x,int y)
{
long long ans = ;
for(int i=x;i>;i-=i&(-i))
ans+=dp[i][y];
return ans;
}
int main()
{
int n,k;scanf("%d%d",&n,&k);
add(,,);
for(int i=;i<n;i++)
{
int x;scanf("%d",&x);x++;
for(int j=k+;j>;j--)
{
long long temp = sum(x,j-);
add(x,j,temp);
}
}
long long ans = sum(n+,k+);
printf("%lld\n",ans);
}

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

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

    C. Subsequences     For the given sequence with n different elements find the number of increasing s ...

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

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

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

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

  4. [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)

    树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...

  5. 【题解】ARC101F Robots and Exits(DP转格路+树状数组优化DP)

    [题解]ARC101F Robots and Exits(DP转格路+树状数组优化DP) 先删去所有只能进入一个洞的机器人,这对答案没有贡献 考虑一个机器人只能进入两个洞,且真正的限制条件是操作的前缀 ...

  6. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】

    题目传送门:http://codeforces.com/contest/799/problem/C C. Fountains time limit per test 2 seconds memory ...

  7. Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)

    题目链接:https://codeforces.com/problemset/problem/799/C 题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建 ...

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

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

  9. CodeForces - 369E Valera and Queries(树状数组)

    CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...

随机推荐

  1. HDU5045-Contest(状压dp)

    题意: 有n个学生,m道题,给出每个同学解出m个问题的概率,在解题过程中每个学生的解题数的差不大于1,求最大能解出题目数的期望 分析: n很小,知道用状压,但是比赛没做出来(脑子太死了,有一个限制条件 ...

  2. 【跟我一起学Python吧】python with statement 进阶理解

    由于之前有一个项目老是要打开文件,然后用pickle.load(file),再处理...最后要关闭文件,所以觉得有点繁琐,代码也不简洁.所以向python with statement寻求解决方法.以 ...

  3. 最短路+线段交 POJ 1556 好题

    // 最短路+线段交 POJ 1556 好题 // 题意:从(0,5)到(10,5)的最短距离,中间有n堵墙,每堵上有两扇门可以通过 // 思路:先存图.直接n^2来暴力,不好写.分成三部分,起点 终 ...

  4. 重新执笔,已是大三!Jekyll自定义主题开发

    前言 “一转眼忘了时间 丢了感觉 黑了世界 再逞强 再疯狂 也会伤 不知 不觉 后知 后觉 然后 发现 失去 知觉 ”——<一吻不天荒> 感言 时间是把双刃剑,什么解决不了,忧烦的,慢慢变 ...

  5. Uva 208 - Firetruck

    [题目链接]http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&p ...

  6. Spark SQL概念学习系列之Spark SQL 优化策略(五)

    查询优化是传统数据库中最为重要的一环,这项技术在传统数据库中已经很成熟.除了查询优化, Spark SQL 在存储上也进行了优化,从以下几点查看 Spark SQL 的一些优化策略. (1)内存列式存 ...

  7. centos 使用mutt 命令发送邮件,随笔非教程

    #按照mutt yum -y install mutt #发送邮件 echo .com -s "邮件主题" -a 附件本地地址

  8. [iOS基础控件 - 6.12.2] Modal

    A.概念 1.也可以用来切换控制器 2.如ActionSheet   除了push之外,还有另外一种控制器的切换方式,那就是Modal 任何控制器都能通过Modal的形式展示出来 Modal的默认效果 ...

  9. Linux命令之env:显示当前用户的环境变量

    Linux系统里的env命令可以显示当前用户的环境变量,还可以用来在指定环境变量下执行其他命令.下面来比较一下set,env和export命令的异同:set命令显示当前shell的变量,包括当前用户的 ...

  10. POJ 1751 Highways (kruskal)

    题目链接:http://poj.org/problem?id=1751 题意是给你n个点的坐标,然后给你m对点是已经相连的,问你还需要连接哪几对点,使这个图为最小生成树. 这里用kruskal不会超时 ...