zoukankan      html  css  js  c++  java
  • CodeForces

    For the given sequence with n different elements find the number of increasing subsequences with k + 1elements. It is guaranteed that the answer is not greater than 8·1018.

    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.

    Examples

    Input
    5 2
    1
    2
    3
    5
    4
    Output
    7

    题意:
    给定包含了 n 个不同元素的序列,找出含有 k + 1 个元素的递增子序列有多少个。数据保证:答案不超过 8·1018 。
    思路:
    dp[a[i]][k]表示以a[i]为结尾,长度为k的子序列的个数.
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #define fuck(x) cout<<#x<<" = "<<x<<endl;
    #define ls (t<<1)
    #define rs ((t<<1)+1)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 100086;
    const int inf = 2.1e9;
    const ll Inf = 999999999999999999;
    const int mod = 1000000007;
    const double eps = 1e-6;
    const double pi = acos(-1);
    
    int a[maxn];
    ll dp[maxn][15];
    
    ll bit[maxn][15];
    int lowbit(int x){
        return x&-x;
    }
    
    void update(int pos,ll val,int t){
        while(pos<maxn){
            bit[pos][t]+=val;
            pos+=lowbit(pos);
        }
    }
    
    ll query(int pos,int t){
        ll ans=0;
        while(pos){
            ans+=bit[pos][t];
            pos-=lowbit(pos);
        }
        return ans;
    }
    
    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        k++;
    
        update(1,1,0);
    
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            a[i]++;
            for(int j=1;j<=k;j++){
                ll ans=query(a[i]-1,j-1);//a[i]-1防止自己接自己
                dp[a[i]][j]=ans;
                update(a[i],dp[a[i]][j],j);
            }
        }
        ll ans=0;
        for(int i=1;i<=n+1;i++){
            ans+=dp[i][k];
        }
        printf("%lld
    ",ans);
    
    
        return 0;
    }
    View Code
  • 相关阅读:
    iot 表索引dump《2》
    heap表和iot表排序规则不同
    Cannot complete the install because one or more required items could not be found.
    iot表输出按主键列排序,heap表不是
    iot 表主键存放所有数据,且按数据插入顺序排序
    iot表和heap表排序规则不同
    org.eclipse.graphiti.ui.editor.DiagramEditorInput.
    Oracle 排序规则
    perl 异步超时 打印错误
    14.6.3 Grouping DML Operations with Transactions 组DML操作
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/10726742.html
Copyright © 2011-2022 走看看