标签:algo and tor pen view isp fun open class
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1024
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31798 Accepted Submission(s): 11278
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define ms(a,b) memset((a),(b),sizeof((a))) 13 using namespace std; 14 typedef long long LL; 15 const double EPS = 1e-8; 16 const int INF = 2e9; 17 const LL LNF = 2e18; 18 const int MAXN = 1e6+10; 19 20 int a[MAXN]; 21 int last_max[MAXN], all_max[2][MAXN]; 22 23 int main() 24 { 25 int n, m; 26 while(scanf("%d%d",&m, &n)!=EOF) 27 { 28 for(int i = 1; i<=n; i++) 29 scanf("%d", &a[i]); 30 31 ms(all_max, 0); 32 ms(last_max, 0); 33 34 int id = 0; 35 for(int i = 1; i<=m; i++) 36 { 37 id = !id; 38 all_max[id][i-1] = -INF; 39 for(int j = i; j<=n; j++) 40 { 41 last_max[j] = max(last_max[j-1], all_max[!id][j-1]) + a[j]; 42 all_max[id][j] = max(all_max[id][j-1], last_max[j]); 43 } 44 } 45 printf("%d\n", all_max[id][n]); 46 } 47 return 0; 48 }
HDU1024 Max Sum Plus Plus —— DP + 滚动数组
标签:algo and tor pen view isp fun open class
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7620385.html