• hdu1024(最大m串子序列)


    m的范围没给,很坑爹

    Max Sum Plus Plus

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 12747    Accepted Submission(s): 4202


    Problem Description
    Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.

    Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767). We define a function sum(i, j) = Si + ... + Sj (1 ≤ i ≤ j ≤ n).

    Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im, jm) maximal (ix ≤ iy ≤ jx or ix ≤ jy ≤ jx is not allowed).

    But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(ix, jx)(1 ≤ x ≤ m) instead. ^_^
     
    Input
    Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
    Process to the end of file.
     
    Output
    Output the maximal summation described above in one line.
     
    Sample Input
    1 3 1 2 3 2 6 -1 4 -2 3 -2 3
     
    Sample Output
    6 8
    Hint
    Huge input, scanf and dynamic programming is recommended.
     
    Author
    JGShining(极光炫影)
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <algorithm>
    #include <math.h>
    #include <map>
    #include <queue>
    #include <sstream>
    #include <iostream>
    using namespace std;
    #define INF 0x3fffffff
    typedef __int64 LL;
    #define N 1000100
    
    LL dp[N][2];
    LL g[N];
    
    int main()
    {
        //freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
        //freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
        int m,n;
        while(scanf("%d%d",&m,&n)!=EOF)
        {
            for(int i=1;i<=n;i++)
            {
                g[i]=-10000000000000;
                dp[i][0]=dp[i][1]=-10000000000000;
            }
            int a=0,b=1;
            for(int i=1;i<=n;i++)
            {
                swap(a,b);
                int tmp;
                scanf("%d",&tmp);
                for(int j=m;j>=1;j--)
                {
                    if(j>i) continue;
                    dp[j][a]=max(dp[j][b],g[j-1])+tmp;
                    if(dp[j][a] > g[j]) g[j] = dp[j][a];
                }
            }
            printf("%I64d
    ",g[m]);
        }
        return 0;
    }
  • 相关阅读:
    网页中的默认按钮
    心动不如行动
    周日骑行广州大学城
    买单车别买重车
    今晚好无聊
    在自行车论坛看到的有趣帖子
    php zend framework 生成 pdf 出现中文乱码
    FPDI Import existing PDF documents into FPDF
    PHP 哈希表,关联数组,遍历方法大全
    zend framework 如何多表查询
  • 原文地址:https://www.cnblogs.com/chenhuan001/p/3148421.html
Copyright © 2020-2023  润新知