• <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 已棄。

            HDOJ 3480 Division

            Division

            Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 999999/400000 K (Java/Others)
            Total Submission(s): 961    Accepted Submission(s): 310


            Problem Description
            Little D is really interested in the theorem of sets recently. There’s a problem that confused him a long time.  
            Let T be a set of integers. Let the MIN be the minimum integer in T and MAX be the maximum, then the cost of set T if defined as (MAX – MIN)^2. Now given an integer set S, we want to find out M subsets S1, S2, …, SM of S, such that



            and the total cost of each subset is minimal.
             

            Input
            The input contains multiple test cases.
            In the first line of the input there’s an integer T which is the number of test cases. Then the description of T test cases will be given.
            For any test case, the first line contains two integers N (≤ 10,000) and M (≤ 5,000). N is the number of elements in S (may be duplicated). M is the number of subsets that we want to get. In the next line, there will be N integers giving set S.

             

            Output
            For each test case, output one line containing exactly one integer, the minimal total cost. Take a look at the sample output for format.

             

            Sample Input
            2 3 2 1 2 4 4 2 4 7 10 1
             

            Sample Output
            Case 1: 1 Case 2: 18
            Hint
            The answer will fit into a 32-bit signed integer.
             

            Source
             


            四邊形不等式優化,我掌握的確實不怎么樣。。。


            #include <iostream>
            #include 
            <cstdio>
            #include 
            <algorithm>

            using namespace std;

            #define  N   10009
            #define  INF 0x3fffffff

            int n, m, a[ N ];

            int solve() {
                    
            static int f[ 2 ][ N ], s[ 2 ][ N ];
                    
            int i, j, k, cur, pre, tmp;

                    cur 
            = 0;
                    
            for ( i = 1; i <= n; ++i ) {
                            f[ cur ][ i ] 
            = (a[i]-a[1])*(a[i]-a[1]);
                            s[ cur ][ i ] 
            = 1;
                    }

                    
            for ( j = 2; j <= m; ++j ) {
                            pre 
            = cur;
                            cur 
            ^= 1;
                            s[ cur ][ n 
            + 1 ] = n - 1;
                            
            for ( i = n; i >= j; --i ) {
                                    f[ cur ][ i ] 
            = INF;
                                    
            for ( k = s[ pre ][ i ]; k <= s[ cur ][ i + 1 ]; ++k ) {
                                            tmp 
            = f[ pre ][ k ] + (a[i]-a[k+1])*(a[i]-a[k+1]);
                                            
            if ( tmp < f[ cur ][ i ] ) {
                                                    f[ cur ][ i ] 
            = tmp;
                                                    s[ cur ][ i ] 
            = k;
                                            }

                                    }

                            }

                    }

                    
            return f[ cur ][ n ];
            }


            int main() {
                    
            int tc, cc, i;
                    scanf( 
            "%d"&tc );
                    
            for ( cc = 1; cc <= tc; ++cc ) {
                            scanf( 
            "%d%d"&n, &m );
                            
            for ( i = 1; i <= n; ++i ) {
                                    scanf( 
            "%d", a + i );
                            }

                            sort( a 
            + 1, a + n + 1 );
                            printf( 
            "Case %d: %d\n", cc, solve() );
                    }

                    
            return 0;
            }

            posted on 2011-03-18 09:38 coreBugZJ 閱讀(1065) 評論(0)  編輯 收藏 引用 所屬分類: ACM

            欧美午夜A∨大片久久 | 久久久久这里只有精品| 欧美一区二区久久精品| 久久毛片一区二区| 久久综合噜噜激激的五月天| 久久青青草原综合伊人| 久久婷婷五月综合色99啪ak| 色综合合久久天天给综看| 久久久久99精品成人片欧美| 久久午夜福利电影| 国产Av激情久久无码天堂| 少妇熟女久久综合网色欲| 狠狠色丁香婷综合久久| 日韩精品久久久久久免费| 91久久九九无码成人网站| jizzjizz国产精品久久| 伊人久久精品影院| 国产精品欧美久久久久无广告| 久久婷婷五月综合色高清| 久久久久亚洲AV无码去区首| 久久久久AV综合网成人| 丁香色欲久久久久久综合网| 亚洲欧美精品一区久久中文字幕| 久久国产亚洲精品无码| 久久亚洲熟女cc98cm| 久久久99精品一区二区| 久久免费香蕉视频| 99久久国产亚洲高清观看2024| 久久综合给合久久狠狠狠97色| 久久精品日日躁夜夜躁欧美| 亚洲午夜久久久影院伊人| 日韩精品无码久久一区二区三| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 亚洲色大成网站WWW久久九九| 久久伊人影视| 中文精品99久久国产| 久久播电影网| 亚洲精品国产综合久久一线| 久久久久久久久久久免费精品| 久久久精品人妻无码专区不卡| 国产三级观看久久|