Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
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.
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的更多相关文章
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...
- Codeforces 946G Almost Increasing Array (树状数组优化DP)
题目链接 Educational Codeforces Round 39 Problem G 题意 给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...
- [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)
树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...
- 【题解】ARC101F Robots and Exits(DP转格路+树状数组优化DP)
[题解]ARC101F Robots and Exits(DP转格路+树状数组优化DP) 先删去所有只能进入一个洞的机器人,这对答案没有贡献 考虑一个机器人只能进入两个洞,且真正的限制条件是操作的前缀 ...
- 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 ...
- Codeforces Round #413 (Div1 + Div. 2) C. Fountains(树状数组维护最大值)
题目链接:https://codeforces.com/problemset/problem/799/C 题意:有 c 块硬币和 d 块钻石,每种喷泉消耗硬币或钻石中的一种,每个喷泉有一个美丽值,问建 ...
- Codeforces 216D Spider's Web 树状数组+模拟
题目链接:http://codeforces.com/problemset/problem/216/D 题意: 对于一个梯形区域,假设梯形左边的点数!=梯形右边的点数,那么这个梯形为红色.否则为绿色, ...
- CodeForces - 369E Valera and Queries(树状数组)
CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...
随机推荐
- source insight 的使用
一,新建工程:project-->new project --> ok--> ok--> close 完成项目的添加 二,sourceInsight的使用 1.跳转到标识定义处 ...
- jdbc:oracle:thin:@192.168.3.98:1521:orcl(详解)
整理自互联网 一. jdbc:oracle:thin:@192.168.3.98:1521:orcljdbc:表示采用jdbc方式连接数据库oracle:表示连接的是oracle数据库thin:表示连 ...
- vc编译器 msvcr.dll、msvcp.dll的含义和相关错误的处理
转自:http://blog.csdn.net/sptoor/article/details/6203376 很久没有写程式设计入门知识的相关文章了,这篇文章要来谈谈程式库 (Library) 连结, ...
- (转载) VS编译duilib项目时候的错误解决方法整理
原文地址:http://blog.csdn.net/x356982611/article/details/30217473 @1:找不到Riched20.lib 用everything等软件搜索下磁盘 ...
- Request、Request.Form和Request.QueryString的区别
Request.Form:获取以POST方式提交的数据(接收Form提交来的数据): Request.QueryString:获取地址栏参数(以GET方式提交的数据) Request:包含以上两种方式 ...
- [微软实习生2014]K-th string
很久之前的事情了,微软2014实习生的在线测试题,记录下来以备后用. 题目描述: Description Consider a string set that each of them consist ...
- 在Toast里面显示图片
关于怎么在Toast里面显示图片,首先自定义一个toast,在自定义一个布局,这个布局你想让toast显示什么样的布局就定义什么样的,然后在自定的布局中放一个ImageView,在把自己自定义 ...
- struts2实现文件上传
Struts2中实现简单的文件上传功能: 第一步:将如下文件引入到WEB_INF/lib目录下面,对应的jar文件可自行下载 第二步:在包test.struts2下建立类UploadFile pack ...
- Mac vim iterm2配色方案
转自:http://www.vpsee.com/2013/09/use-the-solarized-color-theme-on-mac-os-x-terminal/ 相信长期浸泡在终端和代码的小伙伴 ...
- 【Spark学习】Apache Spark for 第三方Hadoop分发版
Spark版本:1.1.1 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4137979.html