• <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>

            a tutorial on computer science

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              21 隨筆 :: 0 文章 :: 17 評論 :: 0 Trackbacks
               神題。比較難想的單調隊列優化。暴力o(N^2)過掉。據說線段樹(n*logN)會掛掉。。需要用到BST。額。。。慚愧了。貼出代碼先。
            #include <stdio.h>

            int N;
            __int64 M;
            int data[100100];
            __int64 sum[
            100100];
            int queue[100100],qhead,qtail;
            __int64 res[
            100100];

            __int64 min(__int64 a,__int64 b)
            {
              
            if(a > b)
                
            return b; 
              
            return a;
            }

            int main()
            {
               
            int i,j;
               
            while(scanf("%d%I64d",&N,&M)!=EOF)
               
            {
                 
            int OK = 1;
                 
            for(i=1;i<=N;i++)
                 
            {
                    scanf(
            "%d",&data[i]);
                    
            if(data[i] > M)
                      OK 
            = 0;
                    sum[i] 
            = sum[i-1+ data[i];
                 }

                 qhead 
            = qtail = 0;
                 
            int st = 1;
                 
            for(i=1;i<=N;i++)
                 
            {
                    
            while(qhead != qtail && data[i] > data[queue[qhead-1]])    
                      qhead
            --;
                        queue[qhead
            ++= i;
                    
            while(sum[i] - sum[st-1> M)
                      st
            ++;
                
                    
            //[st,i] <=M
                    while(qhead != qtail && queue[qtail] < st)
                      qtail
            ++;
                     res[i] 
            = res[st-1+ data[queue[qtail]]; 
                    
                    
            for(j=qtail;j<qhead-1;j++)
                    
            {
                      res[i] 
            = min(res[i],res[queue[j]] + data[queue[j+1]] );
                    }

                 }
             
                 
            if(OK == 1)
                    printf(
            "%I64d\n",res[N]);
                 
            else
                printf(
            "-1\n");
               }

               
            return 0;
            }


            posted on 2012-03-19 18:37 bigrabbit 閱讀(1119) 評論(0)  編輯 收藏 引用
            久久99精品久久久久久水蜜桃| 欧美日韩久久中文字幕| 久久夜色精品国产噜噜亚洲AV| 久久无码人妻一区二区三区午夜| 99久久免费国产精品热| 久久久人妻精品无码一区| 少妇熟女久久综合网色欲| 久久精品天天中文字幕人妻| 久久精品国产99久久丝袜| 亚洲精品乱码久久久久久中文字幕| 久久精品国产亚洲沈樵| 亚洲欧洲中文日韩久久AV乱码| 亚洲狠狠婷婷综合久久久久| 日韩欧美亚洲综合久久影院d3| 伊人色综合九久久天天蜜桃| 久久婷婷综合中文字幕| 亚洲va久久久久| 国产精品综合久久第一页| 久久久av波多野一区二区| 久久天天婷婷五月俺也去| 99久久免费国产精品| 久久国产精品无码一区二区三区| 伊人久久国产免费观看视频 | 久久这里只精品国产99热| 怡红院日本一道日本久久| 国产精品久久久久久久久久影院| 中文字幕亚洲综合久久| 国内精品人妻无码久久久影院 | 色欲综合久久中文字幕网| 精品一久久香蕉国产线看播放| 狠狠色丁香久久综合五月| 丁香色欲久久久久久综合网| 久久夜色精品国产www| 久久青青草原综合伊人| 久久国产精品-国产精品| 久久国产精品无码HDAV | 久久久国产打桩机| 欧美激情精品久久久久久久九九九 | 久久97精品久久久久久久不卡| 久久婷婷五月综合97色 | 精品久久久久成人码免费动漫 |