您的位置:首页 > 产品设计 > UI/UE

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

2015-11-12 20:21 489 查看

[b]C. Subsequences[/b]

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)?

[b]Input[/b]

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.

[b]Output[/b]

Print one integer — the answer to the problem.

[b]Sample Input[/b]

5 2
1
2
3
5
4


[b]Sample Output[/b]

7

HINT

[b]题意
[/b]

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

[b]题解:[/b]

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

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

[b]代码[/b]

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
#define maxn 100105
long long dp[maxn][12];
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 = 0;
for(int i=x;i>0;i-=i&(-i))
ans+=dp[i][y];
return ans;
}
int main()
{
int n,k;scanf("%d%d",&n,&k);
add(1,0,1);
for(int i=0;i<n;i++)
{
int x;scanf("%d",&x);x++;
for(int j=k+1;j>0;j--)
{
long long temp = sum(x,j-1);
add(x,j,temp);
}
}
long long ans = sum(n+1,k+1);
printf("%lld\n",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: