• <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)  編輯 收藏 引用 所屬分類: 樹狀數組

            久久九色综合九色99伊人| 88久久精品无码一区二区毛片 | 精品国产婷婷久久久| 91精品国产高清久久久久久国产嫩草 | 成人久久久观看免费毛片 | 久久久久久毛片免费看| 久久精品综合网| 国产午夜福利精品久久2021| 99久久国语露脸精品国产| 久久久精品久久久久特色影视| 欧美粉嫩小泬久久久久久久 | 热久久视久久精品18| 新狼窝色AV性久久久久久| 伊人久久精品线影院| 伊人久久大香线蕉精品不卡| 久久99精品国产麻豆| 精品欧美一区二区三区久久久| 91精品日韩人妻无码久久不卡| 欧美国产成人久久精品| 国产精品无码久久久久| 国内精品伊人久久久久AV影院| 一本大道久久东京热无码AV| 久久国产精品-久久精品| 亚洲色欲久久久综合网东京热 | 色诱久久av| 国产福利电影一区二区三区久久久久成人精品综合 | 亚洲狠狠婷婷综合久久久久| 久久久久一级精品亚洲国产成人综合AV区| 日韩人妻无码精品久久久不卡| 热久久视久久精品18| 婷婷国产天堂久久综合五月| 久久久久无码中| 国产高潮国产高潮久久久91| 精品一区二区久久| 国产精品福利一区二区久久| 久久久久久久亚洲Av无码| 无码伊人66久久大杳蕉网站谷歌| 亚洲午夜福利精品久久| 亚洲美日韩Av中文字幕无码久久久妻妇 | 中文字幕久久精品无码| 久久久亚洲欧洲日产国码是AV|