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

            coreBugZJ

            此 blog 已棄。

            A short problem, FZU 2011年3月月賽之 D, FZU 2013

            Problem 2013 A short problem

            Time Limit: 1000 mSec    Memory Limit : 32768 KB

            Problem Description

            The description of this problem is very short. Now give you a string(length N), and ask you the max sum of the substring which the length can't small than M.

            Input

            The first line is one integer T(T≤20) indicates the number of the test cases. Then for every case, the first line is two integer N(1≤N≤1000000) and M(1≤M≤N).

            Then one line contains N integer indicate the number. All the number is between -10000 and 10000.

            Output

            Output one line with an integer.

            Sample Input

            2
            5 1
            1 -2 -2 -2 1
            5 2
            1 -2 -2 -2 1

            Sample Output

            1
            -1

            Source

            FOJ有獎月賽-2011年03月



            簡單的動態規劃。
            F[ i ] 表示以  i 結尾的長度大于等于 m 的序列的最大和。
            F[ i ] = max(   F[ i - 1 ] + A[ i ],   A[ i ] + A[ i-1 ] + A[ i-2 ] + ... + A[ i-m+1 ]  );



             1 #include <stdio.h>
             2 
             3 typedef long long Lint;
             4 #define  OFT  "%lld\n"
             5 
             6 #define  L  1000009
             7 
             8 int n, m;
             9 int a[ L ];
            10 Lint s[ L ], f[ L ], ans;
            11 
            12 int main() {
            13         int td, i;
            14         Lint  maxA, maxB;
            15         scanf( "%d"&td );
            16         while ( td-- > 0 ) {
            17                 scanf( "%d%d"&n, &m );
            18                 s[ 0 ] = a[ 0 ] = 0;
            19                 for ( i = 1; i <= n; ++i ) {
            20                         scanf( "%d", a + i );
            21                         s[ i ] = s[ i - 1 ] + a[ i ];
            22                 }
            23                 f[ m - 1 ] = s[ m - 1 ];
            24                 ans = s[ m ];
            25                 for ( i = m; i <= n; ++i ) {
            26                         maxA = f[ i - 1 ] + a[ i ];
            27                         maxB = s[ i ] - s[ i - m ];
            28                         f[ i ] = ( maxA < maxB ? maxB : maxA );
            29                         if ( f[ i ] > ans ) {
            30                                 ans = f[ i ];
            31                         }
            32                 }
            33                 printf( OFT, ans );
            34         }
            35         return 0;
            36 }
            37 

            posted on 2011-03-20 18:40 coreBugZJ 閱讀(1528) 評論(9)  編輯 收藏 引用 所屬分類: ACM

            Feedback

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-21 12:51 xx

            表示沒有理解這樣做的道理  回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-21 12:52 xx

            表示沒有理解為什么這樣做、、自己做法:先求不限制的最大子段和,然后對m+1—n個,每個ans = max(msum+f[i-m], msum);求得其最大值就可以了。  回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-21 17:40 coreBugZJ

            @xx
            若你的 msum 是指當前以 i 結尾的長度為 m 的序列的和,則
            我的 maxA <==> 你的 msum+f[i-m]
            我的 maxB <==> 你的 msum
              回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-21 22:47 銀志圓

            細問 你的狀態轉移方程是?有點不明白f與d之間的關系  回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-21 22:49 銀志圓

            f與s
              回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-21 23:00 coreBugZJ

            @銀志圓
            F[ i ] = max
            (
            F[ i - 1 ] + A[ i ],
            A[ i ] + A[ i-1 ] + A[ i-2 ] + ... + A[ i-m+1 ]
            );
            已加入本文
              回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-22 07:07 銀志圓

            @coreBugZJ
            明白了 Thank you!
              回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-22 09:31 銀志圓

            哥們 fzu第一道題怎么做啊 我的一致wr 汗  回復  更多評論   

            # re: A short problem, FZU 2011年3月月賽之 D, FZU 2013 2011-03-22 15:56 coreBugZJ

            @銀志圓
            第一題是我隊友做的,我還沒看  回復  更多評論   


            大伊人青草狠狠久久| 精品久久久久久无码人妻蜜桃| 99久久www免费人成精品| 国产福利电影一区二区三区久久久久成人精品综合 | 久久精品视频网| 欧美激情精品久久久久久久九九九 | 久久99精品久久久大学生| 国产精品美女久久久久久2018| 99久久夜色精品国产网站| 日韩欧美亚洲综合久久 | 久久精品国产亚洲AV无码麻豆| 久久久久久a亚洲欧洲aⅴ| 色综合久久中文字幕综合网| 久久天天躁狠狠躁夜夜96流白浆 | 精品免费久久久久久久| 青青热久久国产久精品| 久久97精品久久久久久久不卡| 久久国语露脸国产精品电影| 九九热久久免费视频| 色综合久久久久| 97久久精品午夜一区二区| 亚洲国产另类久久久精品小说 | 亚洲AV无码成人网站久久精品大| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久亚洲日韩看片无码| 青春久久| 久久精品无码一区二区三区日韩 | 国产产无码乱码精品久久鸭| 国产69精品久久久久观看软件 | 日日躁夜夜躁狠狠久久AV| 一本大道久久东京热无码AV| 久久久久亚洲精品中文字幕| 91精品观看91久久久久久| 2021精品国产综合久久| 国产亚洲精久久久久久无码| 午夜天堂精品久久久久| 精品无码久久久久久午夜| 久久精品午夜一区二区福利| 色综合久久无码中文字幕| 久久精品国产网红主播| 99久久精品国产麻豆|