• <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 閱讀(1060) 評論(0)  編輯 收藏 引用 所屬分類: ACM

            久久99亚洲综合精品首页| 久久久www免费人成精品| 国产成人AV综合久久| 久久精品无码一区二区三区免费 | 亚洲第一极品精品无码久久| 人妻无码αv中文字幕久久琪琪布| 久久久久亚洲av无码专区 | 成人综合伊人五月婷久久| 66精品综合久久久久久久| 亚洲一级Av无码毛片久久精品| 久久久亚洲欧洲日产国码是AV| 国产V亚洲V天堂无码久久久| 久久有码中文字幕| 久久99国产综合精品免费| 久久激情五月丁香伊人| 国色天香久久久久久久小说| 久久久久久狠狠丁香| 久久人人爽人人爽人人av东京热 | 伊人伊成久久人综合网777| 久久久久无码精品国产| 麻豆久久| 欧美一区二区精品久久| 久久这里只有精品首页| 精品久久久久久久久中文字幕| 无码任你躁久久久久久老妇| 99久久99久久| 99精品久久精品一区二区| 99久久精品免费| 狠狠色婷婷久久一区二区三区| 日韩影院久久| 国产成人精品久久| 99久久精品毛片免费播放| 欧美国产成人久久精品| 久久久久18| 香蕉久久一区二区不卡无毒影院| 国产亚洲精久久久久久无码77777| 91精品婷婷国产综合久久| 精品人妻久久久久久888| 久久久久亚洲av综合波多野结衣| 国产成人综合久久精品尤物| 精品国产一区二区三区久久|