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个点,要求给出有多少条线段包含至少其中一个点. ...
随机推荐
- Android学习笔记一
一.eclipse中的十大快捷键: 1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间的了.这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的 ...
- mount
产品,平台,RS6000, pseries 软件版本, aix 当NFS在NFS客户端加载时,系统会问是使用 soft-mount 还是hard-mount, 它们之间有什么区别? 它们的区别在于当发 ...
- 记录一次MySQL复制问题的处理
备库: mysql> show slave status\G*************************** 1. row *************************** Slav ...
- Oracle数据库导出
一. pl/SQL方式 1.打开plsql,找到工具栏,导出表
- C#中的值类型(value type)与引用类型(reference type)的区别
ylbtech- .NET-Basic:C#中的值类型与引用类型的区别 C#中的值类型(value type)与引用类型(reference type)的区别 1.A,相关概念返回顶部 C#中 ...
- mybatis Mapper XML 文件
MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会立即发现省掉了将近 95% ...
- poj 1505 Copying Books
http://poj.org/problem?id=1505 Copying Books Time Limit: 3000MS Memory Limit: 10000K Total Submiss ...
- cocos2d-x 详解之 CCTexture2D(纹理图片)和 CCTextureCache(纹理缓存)
精灵和动画都涉及到纹理图片的使用,所以在研究精灵与动画之前,我们先来了解一下纹理图片类CCTexture2D和纹理缓存CCTextureCache的原理: 当一张图片被加载到内存后,它是以纹理的形式存 ...
- LeetCode题解——Palindrome Number
题目: 判断一个数字是不是回文数字,即最高位与最低位相同,次高位与次低位相同,... 解法: 求出数字的位数,然后依次求商和求余判断是否相等. 代码: class Solution { public: ...
- 题目1437:To Fill or Not to Fill:贪心算法解决加油站选择问题(未解决)
//贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include& ...