码迷,mamicode.com
首页 > 其他好文 > 详细

[2016-03-28][HDU][1024][Max Sum Plus Plus]

时间:2016-04-01 23:24:46      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

  • 时间:2016-03-28 17:45:33 星期一

  • 题目编号:[2016-03-28][HDU][1024][Max Sum Plus Plus]

  • 题目大意:从n个数字提取出一定数字组成m个部分,使得这个部分的总和最大

  • 分析:

    • dp[i][j]表示前i段计算第j个数字,dp[i][j] = max(dp[i - 1][j - 1] + a[j],dp[i][k] + a[j]);
    1. #include <algorithm>
    2. #include <cstring>
    3. #include <cstdio>
    4. using namespace std;
    5. const int maxn = 1E6 + 10;
    6. int a[maxn];
    7. int dp[maxn],premax[maxn];
    8. int main(){
    9. int n,m;
    10. while(~scanf("%d%d",&m,&n)){
    11. int i;
    12. for(i = 1;i <= n ; ++i){
    13. scanf("%d",&a[i]);
    14. }
    15. memset(dp,0,sizeof(dp));
    16. memset(premax,0,sizeof(premax));
    17. int tmpmax;
    18. for(int ii = 1;ii <= m ; ++ii){
    19. tmpmax = 0x8f8f8f8f;
    20. for(int j = ii; j <= n;++j){
    21. dp[j] = max(dp[j - 1] + a[j],premax[j - 1] + a[j]);
    22. premax[j - 1] = tmpmax;
    23. tmpmax = max(dp[j],tmpmax);
    24. }
    25. }
    26. printf("%d\n",tmpmax);
    27. }
    28. return 0;
    29. }




[2016-03-28][HDU][1024][Max Sum Plus Plus]

标签:

原文地址:http://www.cnblogs.com/qhy285571052/p/52d5b029e63b731ab9ce15d62f9090b9.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!