Hi, I'm back.

This is a realy classic DP problem to code.

1. You have to be crystal clear about what you are going to solve.
2. Apparently there are 2 DP sections
3. Think carefully about recurrence relations
5. Details: take care of indices boundaries - it costed me 1hr to find an indexing bug!
6. Again: think crystal clear before you code!

And, #2593 is exactly the same.

Here is my AC code:

 #include <stdio.h>

 #define MAX_INX 50010
#define Max(a,b) (a)>(b)?(a):(b) int max_sum2(int *pData, int cnt)
{
// DP: Max sum of sub-sequence: dp[i] = MAX(num[i], dp[i-1] + num[i]) // Left -> Right
int lt[MAX_INX] = { };
lt[] = pData[];
for (int i = ; i < cnt; i ++)
{
lt[i] = Max(pData[i], lt[i - ] + pData[i]);
} // Right -> Left
int rt[MAX_INX] = { };
int rtm[MAX_INX] = { };
rt[cnt-] = pData[cnt-];
for (int i = cnt-; i >= ; i--)
{
rt[i] = Max(pData[i], rt[i + ] + pData[i]);
}
rtm[cnt-] = rt[cnt-];
for (int i = cnt-; i >=; i--)
{
rtm[i] = Max(rtm[i+], rt[i]);
} // O(n) to find real max
int ret = -;
for (int i = ; i < cnt - ; i ++)
{
ret = Max(ret, lt[i] + rtm[i+]);
} return ret;
} int main()
{
int nTotal = ;
scanf("%d", &nTotal); while (nTotal--)
{
int num[MAX_INX] = { }; // Get Input
int nCnt = ; scanf("%d", &nCnt);
for (int i = ; i < nCnt; i ++)
{
scanf("%d", num + i);
} printf("%d\n", max_sum2(num, nCnt));
} return ;
}

POJ #2479 - Maximum sum的更多相关文章

  1. POJ 2479 Maximum sum 解题报告

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40596   Accepted: 12663 Des ...

  2. (线性dp 最大连续和)POJ 2479 Maximum sum

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 44459   Accepted: 13794 Des ...

  3. POJ 2479 Maximum sum(双向DP)

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36100   Accepted: 11213 Des ...

  4. poj 2479 Maximum sum (最大字段和的变形)

    题目链接:http://poj.org/problem?id=2479 #include<cstdio> #include<cstring> #include<iostr ...

  5. POJ 2479 Maximum sum POJ 2593 Max Sequence

    d(A) = max{sum(a[s1]..a[t1]) + sum(a[s2]..a[t2]) | 1<=s1<=t1<s2<=t2<=n} 即求两个子序列和的和的最大 ...

  6. [poj 2479] Maximum sum -- 转载

    转自 CSND 想看更多的解题报告: http://blog.csdn.net/wangjian8006/article/details/7870410                         ...

  7. poj 2479 Maximum sum(递推)

     题意:给定n个数,求两段连续不重叠子段的最大和. 思路非常easy.把原串划为两段.求两段的连续最大子串和之和,这里要先预处理一下,用lmax数组表示1到i的最大连续子串和,用rmax数组表示n ...

  8. poj----Maximum sum(poj 2479)

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30704   Accepted: 9408 Desc ...

  9. POJ2479 Maximum sum[DP|最大子段和]

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39599   Accepted: 12370 Des ...

随机推荐

  1. mysql explain用法和结果的含义(转)

    重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...

  2. Day09_面向对象第四天

    1.多态的概念和前提(掌握) 1.概念-什么是多态(掌握)       对象在不同时刻表现出来的不同状态.   2.针对引用类型的理解 编译期间状态和运行期间状态不一样      比如        ...

  3. PAT (Basic Level) Practise:1040. 有几个PAT

    [题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...

  4. List-ApI及详解

    1.API : add(Object o) remove(Object o) clear() indexOf(Object o) get(int i) size() iterator() isEmpt ...

  5. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包

    J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...

  6. WebRTC录音(1)-实现通话双向录音

    最近公司的iPad项目中一个功能点涉及到了VOIP通讯中的录音,需要在已有的WebRTC引擎中增加录音功能,录制通话双方的声音参考了往上一位兄弟的博文(链接在此 http://blog.csdn.ne ...

  7. HTTP.sys漏洞验证及防护

    使用发包工具构造http请求包检测 以fiddler工具为例,构造如下图的请求包: 1 GET http://192.168.174.145/ HTTP/1.12 Host: 192.168.174. ...

  8. 转:bash: /dev/null: Permission denied

    普通用户登录:bash: /dev/null: Permission denied 2012-12-07 16:01:36|  分类: linux |举报 |字号 订阅     Last login: ...

  9. 安装arbotix simulator仿真环境--9

    原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/  周学伟 安装之前:首先确保已经正常制作了ros工作空间并且安装了rbx1功能包: cd ~/catki ...

  10. leetcode 141. Linked List Cycle ----- java

    Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...