3 1 2 3 7 13 7 8 16 21 4 18
9 239
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 const int INF = 0x3f3f3f3f; 5 using namespace std; 6 int a[205]; 7 int sum[205]; 8 int dp[205][205]; 9 int main(){ 10 int n; 11 while(~scanf("%d", &n)){ 12 memset(dp, 0, sizeof(dp)); 13 for(int i = 1; i <= n; i++){ 14 scanf("%d", &a[i]); 15 sum[i] = sum[i-1] + a[i]; 16 } 17 for(int i = 1; i <= n; i++){ 18 for(int j = i-1; j >= 1; j--){ 19 int tmp = INF; 20 for(int k = j+1; k <= i; k++){ 21 tmp = min(tmp, dp[i][k]+dp[k-1][j]+sum[i]-sum[j-1]); 22 } 23 dp[i][j] = tmp; 24 } 25 } 26 printf("%d\n", dp[n][1]); 27 } 28 return 0; 29 }
原文:http://www.cnblogs.com/ACMessi/p/4924615.html