首页 > 代码库 > 1992

1992

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<climits>
 5 using namespace std;
 6 
 7 const int maxn=505;
 8 int b[maxn],dp[maxn][maxn],sum[maxn];
 9 
10 int DP(int m,int k)
11 {
12     int i,j,x,y;
13     for(i=2;i<=k;i++){
14         for(j=i;j<=m;j++){
15             dp[i][j]=INT_MAX;
16             for(x=j-i+1;x>0;x--){
17                 dp[i][j]=min(dp[i][j],max(dp[i-1][j-x],sum[j]-sum[j-x]));
18             }
19         }
20     }
21     return dp[k][m];
22 }
23 
24 
25 int main()
26 {
27     int m,k,cas=0;
28     while(scanf("%d %d",&m,&k)==2){
29         b[0]=0;
30         sum[0]=0;
31         for(int i=1;i<=m;i++){
32             scanf("%d",&b[i]);
33             sum[i]=sum[i-1]+b[i];
34             dp[1][i]=sum[i];
35         }
36         printf("Case %d: %d\n",++cas,DP(m,k));
37     }
38     return 0;
39 }

 

1992