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. 【题解】【数组】【查找】【Leetcode】Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  2. 【题解】【BST】【Leetcode】Validate Binary Search Tree

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  3. 如何用cufflinks 拼出一个理想的注释文件

    后记: cufflinks安装: 下载安装包, 不要下载source code ,直接下载binary.    Source code    Linux x86_64 binary http://cu ...

  4. Educational Codeforces Round 15 D 数学推公式

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #365 (Div. 2) B 前缀和

    B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. MACOS,LINUX,IOS上可用的毫秒级精度时间获取

    二话不说,先上代码 void outputCurrentTime(uint32_t seq,const char* type){ struct timeval t_curr; gettimeofday ...

  7. ajax 城市区域选择三级联动

    <body onLoad="sheng()"><div class="xqbody">    <form action=" ...

  8. 关于sql where id in 转换成数据类型 int 时失败(转)

    有执行sql条件语句where id in(@参数)的时候,如果处理不当,就会出现问题:如下面这个存储过程: alter proc Web_gettwtwgoldgameserverGoldSell@ ...

  9. 什么是html5

    HTML5是用于取代1999年所制定的 HTML 4.01 和 XHTML 1.0 标准的 HTML 标准版本,现在仍处于发展阶段,但大部分浏览器已经支持某些 HTML5 技术.HTML 5有两大特点 ...

  10. 正确答案 全国信息学奥林匹克联赛( ( NOIP2014) 复 赛 模拟题 Day1 长乐一中

    [题目描述]小 H 与小 Y 刚刚参加完 UOIP 外卡组的初赛,就迫不及待的跑出考场对答案."吔,我的答案和你都不一样!",小 Y 说道,"我们去找神犇们问答案吧&qu ...