标签:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 #define N 106 8 #define inf 1<<26 9 int a[N]; 10 int dp[N][N]; 11 int sum[N]; 12 int main() 13 { 14 int t; 15 int ac=0; 16 scanf("%d",&t); 17 while(t--) 18 { 19 memset(sum,0,sizeof(sum)); 20 int n; 21 scanf("%d",&n); 22 for(int i=1;i<=n;i++) 23 scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i]; 24 25 memset(dp,0,sizeof(dp)); 26 for(int i=1;i<=n;i++) 27 { 28 for(int j=i+1;j<=n;j++) 29 { 30 dp[i][j]=inf; 31 } 32 } 33 for(int len=1;len<=n;len++) 34 { 35 for(int i=1;i+len<=n;i++) 36 { 37 int j=i+len; 38 for(int k=1;k<=j-i+1;k++) 39 { 40 dp[i][j]=min(dp[i][j],dp[i+1][i+k-1]+dp[i+k][j]+k*(sum[j]-sum[i+k-1])+a[i]*(k-1)); 41 } 42 } 43 } 44 printf("Case #%d: ",++ac); 45 printf("%d\n",dp[1][n]); 46 } 47 return 0; 48 }
hdu 4283 You Are the One(区间dp)
标签:
原文地址:http://www.cnblogs.com/UniqueColor/p/4741150.html