zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    AS3.0中的反射概念
    AS3.0 关于用URLLoader加载外部图片
    AS3.0 Socket编程
    AS3.0 ByteArray详解
    Starling 1.3正式发布
    AS3.0中通过ApplicationDomain类获得被加载swf
    Delphi编程使程序不在系统任务条上出现(转)
    手把手教delphi:写你的dll文件(1)
    全面控制任务栏以及桌面代码
    Delphi中资源文件使用详解(转)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4960186.html
Copyright © 2011-2022 走看看