#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <queue>
#include <map>
#define FOP freopen("in","r",stdin)
#define inf 0x3f3f3f3f
#define ll __int64
#define eps 1e-8
using namespace std;
const int N = 110;
int val[N];
int sum[N];
int dp[N][N];
int main()
{
// FOP;
int T,cas=1;
int i,j,l,k,n;
int temp1,temp2,temp3;
scanf( "%d" , &T );
while( T-- )
{
printf( "Case #%d: " , cas++ );
memset( val , 0 , sizeof val );
memset( sum , 0 , sizeof sum );
memset( dp , 0 , sizeof dp );
scanf( "%d" , &n );
for( i = 1 ; i <= n ; i++ )
{
scanf( "%d" , &val[i] );
sum[i] = sum[i-1] + val[i];
}
for( i = 1 ; i <= n ; i++ )
for( j = i+1 ; j <= n ; j++ )
dp[i][j] = inf;
for( l = 1 ; l <= n-1 ; l++ )
{
for( i = 1 ; i <= n-l ; i++ )
{
j = i+l;
for( k = 1 ; k <= j-i+1 ; k++ )
{
temp1 = (k-1) * val[i];
temp2 = dp[i+1][i+k-1];
temp3 = dp[i+k][j] + k * ( sum[j] - sum[i+k-1] );
dp[i][j] = min( dp[i][j] , temp1+temp2+temp3 );
}
}
}
printf("%d\n" , dp[1][n]);
}
return 0;
}
HDU4283 You Are the One
最新推荐文章于 2021-11-29 13:13:12 发布