http://acm.hdu.edu.cn/showproblem.php?pid=4283
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1575 Accepted Submission(s): 748
#include<iostream> #include<cstdio> #include<cstring> #define inf 1<<27 using namespace std; int dp[105][105]; int main() { int i,t,val[105],n,sum[105],j,k,g,r; scanf("%d",&t); for(r=1;r<=t;r++) { scanf("%d",&n); memset(dp,0,sizeof(dp)); memset(sum,0,sizeof(sum)); for(i=1;i<=n;i++) { scanf("%d",&val[i]); sum[i]=val[i]+sum[i-1]; } for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) dp[i][j]=inf; for(k=1;k<=n;k++) { for(i=1;i<=n-k;i++) { j=i+k; for(g=i;g<=j;g++) dp[i][j]=min(dp[i][j],val[i]*(g-i)+dp[i+1][g]+dp[g+1][j]+(sum[j]-sum[g])*(g-i+1)); } } printf("Case #%d: %d\n",r,dp[1][n]); } return 0; }
HDU-4283 You Are the One,布布扣,bubuko.com
原文:http://www.cnblogs.com/cancangood/p/3869819.html