2521: Monkey and fruits
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| 3s | 8192K | 365 | 62 | Standard |
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
Problem Source: 221_Keenas
This problem is used for contest: 121
#include<stdio.h>
#include<string.h>
int m[110][110];
int sum[110],b[110];
int main()
{
int n,i,j,k,r;
while(scanf("%d",&n)==1)
{
sum[0]=0;
memset(m,0,sizeof(m));
for(i=1;i<=n;i++) {scanf("%d",&b[i]);sum[i]=sum[i-1]+b[i];}
for(r=1;r<n;r++)
{
for(i=1;i+r<=n;i++)
{
j=i+r;
m[i][j]=m[i+1][j]+sum[j]-sum[i-1];
for(k=i+1;k<j;k++)
{
int t=m[i][k]+m[k+1][j]+sum[j]-sum[i-1];
if(t<m[i][j]) m[i][j]=t;
}
}
}
printf("%d/n",m[1][n]);
}
return 0;
}
解决猴子如何用最少体力将分散的果堆合并成一堆的问题。输入果堆数量及各堆果子数,输出最小体力消耗。
1211

被折叠的 条评论
为什么被折叠?



