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

            色综合久久精品中文字幕首页| 人妻中文久久久久| 久久亚洲精品成人无码网站| 久久天天躁狠狠躁夜夜avapp | 亚洲AV日韩精品久久久久久| 久久精品国产亚洲av麻豆小说| AV无码久久久久不卡网站下载 | 久久久一本精品99久久精品88| 亚洲AV无一区二区三区久久| 亚洲国产精品久久66| 99久久香蕉国产线看观香| 久久精品男人影院| 久久精品国产亚洲av麻豆蜜芽| 国产精品久久久久久福利69堂| 婷婷久久精品国产| 精品久久久久久久| 精品国产99久久久久久麻豆| 国产精品久久久久一区二区三区 | 久久综合综合久久狠狠狠97色88| 久久久久久免费视频| 中文字幕久久欲求不满| 亚洲欧洲日产国码无码久久99| 99久久伊人精品综合观看| 日韩av无码久久精品免费| 亚洲精品国产第一综合99久久| 热99re久久国超精品首页| 奇米影视7777久久精品| 久久91精品国产91| 亚洲伊人久久综合中文成人网| 色综合合久久天天综合绕视看| 7777久久亚洲中文字幕| 日韩AV无码久久一区二区| 狠狠色综合网站久久久久久久高清| 久久99精品久久久久久水蜜桃 | 久久人人爽人人爽人人片AV麻豆| 久久香蕉综合色一综合色88| 精品久久无码中文字幕| 99久久精品日本一区二区免费| 久久久久高潮毛片免费全部播放 | 久久婷婷综合中文字幕| 精品午夜久久福利大片|