• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 97, 文章 - 22, 評論 - 81, 引用 - 0
            數據加載中……

            HDU 2227 Find the nondecreasing subsequences

            題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=2227
            /*
            題意:
                給定N(N <= 100000)個數字ai,找出這個序列中有多少非遞減序列。

            解法:
            樹狀數組 + 動態規劃

            思路:
                如果n的值小于等于1000,我們可以用動態規劃來解,dp[i]表示
            到第i個位置能夠找到的非遞減序列的解的數量,那么有狀態轉移方程
            dp[i] = sum{ dp[j], j<i, a[j]<=a[i] },這個時間復雜度是O(n^2)
            ,但是n很大,所以不能采用,但是我們觀察到這個轉移方程是以求和
            的形式出現,并且有一個限制條件就是a[j] <= a[i],那么如果我們把
            數字映射到下標,就可以輕松的通過樹狀數組的成段求和來統計了。
                具體做法是:由于數字較大,我們可以先將所有數字離散化,這樣
            每個數字就有一個 <= n 的標號,然后這個標號就可以對應樹狀數組的
            下標了,每次從左往右在樹狀數組中統計比當前數小或者相等的數的個
            數,然后將當前數字(離散后的數字)插入到樹狀數組中,循環結束,
            累加和就是最后的答案了。

            */


            #include 
            <iostream>
            #include 
            <cstdio>
            #include 
            <cstring>
            #include 
            <algorithm>
            using namespace std;

            typedef unsigned 
            int ui;
            typedef __int64 ll;

            #define maxn 100010
            #define mod 1000000007

            int n;
            ui val[maxn], t[maxn];
            ll c[maxn];
            int tot;

            int lowbit(int x) {
                
            return x & (-x);
            }


            void add(int pos, ll v) {
                
            while(pos <= tot) {
                    c[pos] 
            += v; if(c[pos] >= mod ) c[pos] %= mod;
                    pos 
            += lowbit(pos);
                }

            }


            ll sum(
            int pos) {
                
            int s = 0;
                
            while(pos >= 1{
                    s 
            += c[pos]; if(s >= mod ) s %= mod;
                    pos 
            -= lowbit(pos);
                }

                
            return s;
            }


            int Bin(ui v) {
                
            int l = 1;
                
            int r = tot;
                
            while(l <= r) {
                    
            int m = (l + r) >> 1;
                    
            if(v == t[m])
                        
            return m;
                    
            if(v > t[m])
                        l 
            = m + 1;
                    
            else
                        r 
            = m - 1;
                }

            }


            int main() {
                
            int i;
                
            while(scanf("%d"&n) != EOF) {
                    
            for(i = 0; i < n; i++{
                        scanf(
            "%u"&val[i]);
                        t[i
            +1= val[i];
                    }

                    tot 
            = 0;
                    sort(t
            +1, t+1+n);
                    
            for(i = 1; i <= n; i++{
                        
            if(i==1 || t[i] != t[i-1]) {
                            t[
            ++tot] = t[i];
                            c[tot] 
            = 0;
                        }

                    }

                    
            for(i = 0; i < n; i++{
                        val[i] 
            = Bin(val[i]);
                    }

                    ll ans 
            = 0;
                    add(
            11);
                    
            for(i = 0; i < n; i++{
                        ll x 
            = sum(val[i]);
                        ans 
            += x;  if(ans >= mod) ans %= mod;
                        add(val[i], x);
                    }

                    printf(
            "%d\n", (int)ans);
                }

                
            return 0;
            }

            posted on 2011-04-06 12:11 英雄哪里出來 閱讀(1484) 評論(0)  編輯 收藏 引用 所屬分類: 樹狀數組

            青青青伊人色综合久久| 久久婷婷五月综合成人D啪| 久久乐国产综合亚洲精品| 久久亚洲国产精品成人AV秋霞| 久久综合久久自在自线精品自| 欧美久久精品一级c片片| 99久久婷婷国产一区二区| 久久精品国产亚洲av麻豆蜜芽| 久久精品中文字幕久久| 久久久无码精品亚洲日韩软件| 久久无码中文字幕东京热| 久久99热国产这有精品| 久久久久久亚洲AV无码专区| 亚洲国产成人久久一区久久| 91精品久久久久久无码| 亚洲国产精品无码久久久久久曰| 久久综合国产乱子伦精品免费| 久久国产热这里只有精品| 久久99久久无码毛片一区二区| 久久99精品国产一区二区三区| 久久伊人色| 品成人欧美大片久久国产欧美...| 久久久久99精品成人片直播| 亚洲国产成人精品女人久久久 | 亚洲精品无码久久久久去q| 日韩美女18网站久久精品| 久久成人国产精品二三区| 亚洲国产精品无码久久一区二区 | 99久久婷婷国产综合亚洲| 精品熟女少妇AV免费久久| 久久久久久亚洲精品无码| 国产—久久香蕉国产线看观看| 亚洲精品高清久久| 久久成人国产精品二三区| 2021久久精品国产99国产精品| 亚洲成人精品久久| 久久精品嫩草影院| 国产精品成人久久久久三级午夜电影 | 久久亚洲国产午夜精品理论片| 久久综合狠狠综合久久| 久久香蕉超碰97国产精品|