标签:direct desc line inf href min nes memory ++
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1005,inf=1e9+10; int a[N],pre[N]; int dp[N][N]; int main() { int T,cas=1; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); pre[i]=pre[i-1]+a[i]; } memset(dp,0,sizeof(dp)); for(int i=0;i<=n;i++) { for(int j=i;j<=n;j++) dp[i][j]=inf; } for(int i=1;i<=n;i++) { for(int j=1;j+i-1<=n;j++) { int st=j; int en=j+i-1; for(int k=st;k<=en;k++) { int p=k-st+1; dp[st][en]=min(dp[st][en],dp[st+1][k]+dp[k+1][en]+p*a[st]+(pre[en]-pre[k])*p); } } } printf("Case #%d: %d\n",cas++,dp[1][n]-(pre[n])); } return 0; } /* 2 5 1 2 3 4 5 5 5 4 3 2 2 */
标签:direct desc line inf href min nes memory ++
原文地址:http://www.cnblogs.com/jhz033/p/6129077.html