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

            国产成人精品久久免费动漫 | 精品久久国产一区二区三区香蕉 | 久久综合偷偷噜噜噜色| 香蕉99久久国产综合精品宅男自 | 久久美女网站免费| 久久精品国产一区二区三区 | 97精品伊人久久大香线蕉app| 久久久无码精品亚洲日韩按摩| 久久精品国产亚洲AV高清热| 韩国三级大全久久网站| 精品久久久久久无码中文野结衣| 久久久久国色AV免费观看| 久久乐国产综合亚洲精品| 97久久香蕉国产线看观看| 久久精品国产亚洲AV不卡| 色欲av伊人久久大香线蕉影院| 久久亚洲精品中文字幕三区| 香蕉久久影院| 精品久久久久中文字幕一区| 国产亚洲精久久久久久无码77777| 九九久久自然熟的香蕉图片| 久久综合九色欧美综合狠狠| 久久99精品久久久久久久久久| 久久久噜噜噜久久| 久久久国产精品福利免费| 欧美日韩精品久久久免费观看| 欧美伊香蕉久久综合类网站| 亚洲欧美精品一区久久中文字幕 | 精品久久久久久久中文字幕| 久久精品国产亚洲精品2020| 四虎影视久久久免费| 99热都是精品久久久久久| 99久久无码一区人妻a黑| 久久久午夜精品福利内容| 久久99精品久久久久久齐齐| 久久电影网一区| 大伊人青草狠狠久久| 久久中文字幕人妻熟av女| 日韩十八禁一区二区久久| 色综合久久综合网观看| 青青青伊人色综合久久|