Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21540 Accepted Submission(s): 7215
/* ID: LinKArftc PROG: 1024.cpp LANG: C++ */ #include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdio> #include <string> #include <climits> #include <utility> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define randin srand((unsigned int)time(NULL)) #define input freopen("input.txt","r",stdin) #define debug(s) cout << "s = " << s << endl; #define outstars cout << "*************" << endl; const double PI = acos(-1.0); const double e = exp(1.0); const int inf = 0x3f3f3f3f; const int INF = 0x7fffffff; typedef long long ll; const int maxn = 1000010; int num[maxn], dp[maxn], last[maxn]; int main() { int n, m; while (~scanf("%d %d", &m, &n)) { memset(dp, 0, sizeof(dp)); memset(last, 0, sizeof(last)); for (int i = 1; i <= n; i ++) scanf("%d", &num[i]); int ma; for (int i = 1; i <= m; i ++) {//分成i段 ma = INT_MIN; for (int j = i; j <= n; j ++) {//前j个数 dp[j] = max(dp[j-1], last[j-1]) + num[j];//dp[j]表示前j个划分成i段最大值,last[j-1]表示前j-1个划分成i-1段最大值 last[j-1] = ma; ma = max(ma, dp[j]); } last[n] = ma; } printf("%d\n", ma); } return 0; }
原文:http://www.cnblogs.com/LinKArftc/p/4963191.html