标签:using rip http 枚举 element 分析 输出 put max
4 1 2 3 4Sample Output
19
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; const int maxn = 1000 + 100; #define INF 0x3f3f3f3f int main() { int n; scanf("%d", &n); int sum[maxn]; int f[maxn][maxn]; memset(f, 0, sizeof(f)); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); sum[i] = sum[i-1]+x; } for (int len = 2; len <= n; len++) { for (int i = 1; i <= n; i++) { int j = i+len-1; f[i][j] = INF; for (int k = i; k < j; k++) f[i][j] = min(f[i][j], f[i][k]+f[k+1][j] + sum[j] - sum[i-1]); } } printf("%d\n", f[1][n]); }
标签:using rip http 枚举 element 分析 输出 put max
原文地址:https://www.cnblogs.com/ruthank/p/8881817.html