• <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>
            posts - 195,  comments - 30,  trackbacks - 0
            After culling his most favorite fruits from the trees in an orchard,Keen AS, a mischievous monkey, is confused of the way in which he can combine these piles of fruits into one in the most laborsaving manner. Each turn he can merely combine any two piles into a larger one. Obviously, by combining N-1 times for N piles of fruits, one pile results eventually. It always takes AS a certain quantity of units of stamina, which equals to the sum of the amounts of fruits in each of the two piles combined, to complete a combination. For instance, given three piles of fruits, containing 1, 2, and 9 fruits respectively, the combination of 1 and 2 would cost 3=1+2 units of stamina, and two piles-3 and 9-are resulted; finally, combining them would cost another 12=3+9 units of stamina, and the total units of stamina taken in the whole procedure is 15=3+12. Surely there are many a possible means to combine these three piles; however, it can be proved that 15 is the minimum amount of units of stamina in demand, and that is what your program is required to do. in this problem ,the fruits are put in a strait line. A pile of fruits 'P' can only combined with the rightest pail on the left of P or the leftest on the right of P, and the united pile will at the position of the bigger one.

            Input

            The input file consists of many test cases. The first line contains an integer N (<=100), indicating the number of piles, and the second line contains N integers, each of which represents the amount of fruits in a pile. no integer will more than 10000, the sequence of integer also means the location of the piles.

            Output

            Your program should print the minimum amount of units of stamina that are required to combine these piles of fruits into one on request.

            Sample Input

            3
            1 2 9
            

            Sample Output

            15
            

            典型的石子合并問(wèn)題。
            #include<stdio.h>
            int a[101][101],sum[101];
            int stone[101];
            int main()
            {
                int n,i,j,k,flag,l,t;
                while(scanf("%d",&n)!=EOF)
                {
                    for(i=1;i<=n;i++)
                    scanf("%d",&stone[i]);
                    sum[0]=0;
                    for(i=1;i<=n;i++)
                    {
                        sum[i]=sum[i-1]+stone[i];      
                        a[i][i]=0;
                    }
                    for(l=1;l<=n-1;l++)
                    for(i=1;i<=n-l;i++)
                    {
                        flag=0;
                        j=i+l;
                        for(k=i;k<j;k++)                              
                        {
                            t=a[i][k]+a[k+1][j]+sum[j]-sum[i-1];
                            if(!flag)
                            {
                                flag=1;
                                a[i][j]=t;
                            }
                            else if(t<a[i][j])
                            a[i][j]=t;
                        }
                    }
                    printf("%d\n",a[1][n]);
                }
                return 0;
            }
            posted on 2009-06-30 21:01 luis 閱讀(474) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 動(dòng)態(tài)規(guī)劃
            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            99久久成人国产精品免费| 一本综合久久国产二区| 久久婷婷五月综合97色直播| 久久精品亚洲一区二区三区浴池 | 婷婷久久综合九色综合绿巨人| 狠狠色婷婷综合天天久久丁香 | 久久午夜福利电影| 激情综合色综合久久综合| 欧洲国产伦久久久久久久| 久久精品成人免费观看97| 久久久WWW免费人成精品| 国内精品久久久久久麻豆| 国产激情久久久久影院| 久久夜色撩人精品国产小说| 久久强奷乱码老熟女| 中文成人无码精品久久久不卡| 综合久久精品色| 麻豆成人久久精品二区三区免费| 99久久精品国产一区二区| 日本福利片国产午夜久久| 久久精品一区二区三区中文字幕| 久久久久噜噜噜亚洲熟女综合 | 综合久久一区二区三区| 久久久久亚洲精品天堂| 久久久青草青青亚洲国产免观| 久久久久亚洲精品无码网址| 久久久久久久久66精品片| 91精品国产91久久久久久蜜臀| 久久se精品一区精品二区国产| 精品久久久久成人码免费动漫| 国内精品久久久久影院日本 | 97视频久久久| 国产一区二区三区久久| 热综合一本伊人久久精品| 久久天天躁狠狠躁夜夜躁2O2O| 国产成人精品久久亚洲高清不卡| 国产精品久久久久蜜芽| 久久久久中文字幕| 蜜臀久久99精品久久久久久小说| 国产一区二区三区久久| 国产成人精品综合久久久|