• 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.

    ⋅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][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
    ",ans);
    }
  • 相关阅读:
    (五)Redis在项目中应用
    股票收益最大问题
    (四)redigo
    (三)go-sql-driver
    为什么TCP要3次握手?4次挥手?
    分支预测
    事务隔离级别说明
    剑指offer解题思路锦集11-20题
    C++中的二义性问题
    memcached Vs redis
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4960186.html
Copyright © 2020-2023  润新知