zoukankan      html  css  js  c++  java
  • HDU 5542 The Battle of Chibi (ccpc 南阳 C)(DP 树状数组 离散化)

    题意:找出长度为n的序列中 递增序列长度为m的个数。

    分析:dp[i][j] = sum(dp[1][j-1]+dp[2][j-1]+~+dp[i-1][j-1])

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <cmath>
    #include <cstdlib>
    #include <map>
    
    using namespace std;
    
    const int Mod = 1000000007;
    int a[1005];
    int b[1005];
    int dp[1005][1005];
    
    int sum(int nn, int mm)
    {
        int ans=0;
        while(nn)
        {
            ans += dp[nn][mm];
            ans%=Mod;
            nn -= nn&(-nn);
        }
        return ans;
    }
    void update(int n, int nn, int mm, int x)
    {
        while(nn<=n)
        {
            dp[nn][mm] += x;
            dp[nn][mm] %= Mod;
            nn+=nn&(-nn);
        }
    }
    
    int main()
    {
        int t;
        int n, m;
        scanf("%d", &t);
        for(int tt=1; tt<=t; tt++)
        {
            scanf("%d %d", &n, &m);
            for(int i=1; i<=n; i++)
            {
                scanf("%d", &a[i]);
                b[i] = a[i];
            }
            sort(b+1, b+n+1);
            int k = unique(b+1, b+n+1)-b-1;
            for(int i=1; i<=n; i++)
            {
                a[i] = lower_bound(b+1, b+n+1, a[i])-b;
            }
            memset(dp, 0, sizeof(dp));
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=min(i,m); j++)
                {
                    if(j==1)
                    {
                        update(n, a[i], j, 1);
                        continue;
                    }
                    int x = sum(a[i]-1, j-1);
                    update(n, a[i], j, x);
                }
            }
            int ans = sum(n, m);
            printf("Case #%d: %d
    ", tt, ans);
        }
    
        return 0;
    }
  • 相关阅读:
    斜二进制数
    贝贝的波浪数
    1058: 电文保密
    1065: 贝贝的加密工作
    低危漏洞- X-Frame-Options Header未配置
    1064: 不明飞行物(ufo)
    支付
    1067: 密室寻宝(find)
    c++10进制转换为任意2-16进制数字
    1066: 单词游戏(game)
  • 原文地址:https://www.cnblogs.com/mengzhong/p/5483182.html
Copyright © 2011-2022 走看看