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

            典型的石子合并問題。
            #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 閱讀(487) 評論(0)  編輯 收藏 引用 所屬分類: 動態規劃
            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久人妻一区精品| 国产精品久久久亚洲| 精品无码久久久久久国产| 久久精品国产99国产电影网 | 青青青国产精品国产精品久久久久 | 亚洲精品乱码久久久久久按摩| 久久久亚洲AV波多野结衣| 久久久久久久久无码精品亚洲日韩| 久久婷婷五月综合色高清| 亚洲成人精品久久| 无码人妻久久一区二区三区蜜桃 | 日韩美女18网站久久精品| 一级做a爰片久久毛片免费陪| 亚洲精品乱码久久久久66| 欧美久久精品一级c片片| 伊人久久大香线蕉综合热线| 国产91色综合久久免费分享| 午夜精品久久久久久久无码| 久久精品国产清高在天天线| 欧美久久久久久午夜精品| 色欲综合久久躁天天躁蜜桃| 国内精品欧美久久精品| 五月丁香综合激情六月久久| 香蕉99久久国产综合精品宅男自 | 久久综合久久伊人| 精品熟女少妇aⅴ免费久久| 久久亚洲天堂| 久久综合欧美成人| 久久天天躁狠狠躁夜夜96流白浆| 久久精品视屏| 国产日韩欧美久久| 国产一久久香蕉国产线看观看| 狠狠综合久久综合88亚洲| 久久精品中文字幕一区| 99久久婷婷国产综合精品草原 | 久久国产成人午夜aⅴ影院| 久久久久亚洲av无码专区| 伊人久久大香线蕉亚洲五月天| 久久99国产精品久久99小说| 日本亚洲色大成网站WWW久久| 久久久久亚洲AV无码去区首|