HDU_1024_dp
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24252 Accepted Submission(s): 8312
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. ^_^
Process to the end of file.
2 6 -1 4 -2 3 -2 3
8
Huge input, scanf and dynamic programming is recommended.
#include<cstdio>
#include<iostream>
#include<malloc.h>
#include<cstring>
#include<map>
#include<string>
using namespace std;
#define LL long long
#define INF 0x7fffffff int value[];
LL dp[];
LL maxn[]; int main()
{
int m,n,num;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(dp,,sizeof(dp));
memset(maxn,,sizeof(maxn));
for(int i=; i<=n; i++)
scanf("%d",&value[i]);
LL ans=;
LL temp;
for(int i=; i<=m; i++)
{
temp=-INF;
for(int j=i; j<=n; j++)
{
dp[j]=max(dp[j-],maxn[j-])+value[j];
maxn[j-]=temp;
temp=max(temp,dp[j]);
}
//cout<<dp[0][3]<<endl; }printf("%I64d\n",temp);
}
return ;
}
HDU_1024_dp的更多相关文章
随机推荐
- 『GCD』详解
2. GCD 任务和队列 学习 GCD 之前,先来了解 GCD 中两个核心概念:任务和队列. 任务:就是执行操作的意思,换句话说就是你在线程中执行的那段代码.在 GCD 中是放在 block 中的.执 ...
- A program to print Fahrenheit-Celsius table with floating-point values
我的主力博客:半亩方塘 Another program to print Fahrenheit-Celsius table with decimal integer This program is p ...
- Interval 计时器
语法: setInterval(代码,交互时间); 在执行时,从载入页面后每隔指定的时间执行代码. clearInterval( setInterval() 返回的 ID 值 ): 取消计时器 < ...
- A Go library implementing an FST (finite state transducer)——mark下
https://github.com/couchbaselabs/vellum Building an FST To build an FST, create a new builder using ...
- [Codeforces 339D] Xenia and Bit Operations
[题目链接] https://codeforces.com/problemset/problem/339/D [算法] 线段树模拟即可 时间复杂度 :O(MN) [代码] #include<bi ...
- Joseph问题 (线段树)
Joseph问题似乎是入门题,就是那个报数出圈的问题,不过它暴力模拟的复杂度是O(nm)的,如果题目的数据范围达到了30000,那就超时了.怎么用线段树维护呢? 我们可以这么考虑,每次我们其实要查询在 ...
- 编译Ruby2.0 问题解决
compiling readline.creadline.c: In function ‘Init_readline’:readline.c:1886:26: error: ‘Function’ un ...
- HDU 2544 最短路 (Floyd)
题意:略. 析:由于 n 比较小,所以我们可以用Floyd,完全不会超时. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240000 ...
- Eclipse使用Tomcat发布项目时出现YadisException异常解决方案
调整使用Eclipse的JDK版本,大概JDK版本过低会出现这个org.openid4java.discovery.yadis.YadisException: 0x704: I/O transport ...
- 赋予option元素点击事件后,点击select时却触发了option事件。如何解决?
将select的优先级提到option之前就可以了. 方法:为select元素添加position:relative: <select class="adt" name=&q ...