• <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 閱讀(477) 評論(0)  編輯 收藏 引用 所屬分類: 動(dòng)態(tài)規(guī)劃
            <2011年12月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            中文字幕日本人妻久久久免费| 久久久久免费精品国产| 国产精品99久久久精品无码| 久久婷婷国产综合精品| 精品久久久久久久久久久久久久久| 香蕉99久久国产综合精品宅男自 | 国产成人无码精品久久久久免费| 亚洲国产精品成人AV无码久久综合影院| 亚洲午夜福利精品久久| 狠狠狠色丁香婷婷综合久久五月| 青青草国产97免久久费观看| 粉嫩小泬无遮挡久久久久久| 日韩精品久久久久久久电影| AA级片免费看视频久久| 久久国产乱子伦免费精品| 欧美一区二区久久精品| 99久久精品九九亚洲精品| 久久精品无码午夜福利理论片| 亚洲国产高清精品线久久| 91亚洲国产成人久久精品| 久久精品国产亚洲AV高清热| 精品久久亚洲中文无码| 亚洲人成电影网站久久| 久久99精品国产麻豆婷婷| 久久99热精品| 99999久久久久久亚洲| 国内精品久久人妻互换| 人人狠狠综合久久88成人| 亚洲精品无码久久久久去q| 久久久久亚洲AV片无码下载蜜桃| 亚洲国产成人久久综合野外| 久久久WWW成人| 婷婷久久综合九色综合绿巨人| 久久精品中文字幕有码| 热综合一本伊人久久精品| 国产精品青草久久久久福利99| 国产精品伊人久久伊人电影| 久久久WWW免费人成精品| 亚洲欧美日韩精品久久亚洲区| 久久久久亚洲爆乳少妇无| 亚洲国产香蕉人人爽成AV片久久|