hdu 1024 dp滚动数组
2024-08-26 10:25:15
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <vector> using namespace std;
#define INF 0x7fffffff
#define LL long long
#define MAX(a,b) ((a)>(b))? (a):(b)
struct node{
int x,y,w;
};
int a[1000005];
LL dp[1000005];//dp[i] 为前i个里面的是包含a[i]的m个子端的最大值这里面用了滚动数组,
LL cc[1000005];//前i个分成m个子端的最大和的位置
int main(){
int n,m;
while(cin >> m >> n){
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
dp[i] = 0;
cc[i] = 0; }
dp[0] = 0;
cc[0] = 0;
LL mmax;
for(int i = 1;i <= m;i++){
mmax = -INF;
for(int j = i;j <= n;j++){
dp[j] = MAX(dp[j-1]+a[j],cc[j-1]+a[j]);
cc[j-1] = mmax;
mmax = MAX(mmax,dp[j]);
}
} printf("%I64d\n",mmax);
}
return 0;
}
最新文章
- HTML学习笔记--HTML的语法【1】
- 【转】TextView长按复制实现方法小结
- 最近点对问题 POJ 3714 Raid &;&; HDOJ 1007 Quoit Design
- 百度地图API示例之设置地图显示范围
- JSP表单处理
- HDU 4497 数论+组合数学
- Codeforces Gym 100002 B Bricks 枚举角度
- 实现微信文章页面 http://mp.weixin.qq.com/s?__biz=MjM5MDI3OTAwMg==&;amp;mid=200337417&;amp;idx=1&;amp;sn=5959ed1d722c7da66b
- UIButton 按钮文字左对齐
- iOS 返回到指定的ViewController
- C++ Code_combobox
- js生成验证码并且判断
- 微信面试题-获取元素的最终background-color
- 浅谈卷积神经网络及matlab实现
- 《并行程序设计导论》——MPI(Microsoft MPI)(1):Hello
- Android项目的targetSDK>;=23,在低于Android6.0的部分测试机(类似华为)上运行时出现的系统权限问题
- in和hasOwnProperty的区别
- git 配置ssh key
- java 之2D过气游戏类的写法
- SQL注入之Sqli-labs系列第十八关(基于错误的用户代理,头部POST注入)
热门文章
- mysql 笔记(一)
- ref:如何在大量jar包中搜索特定字符
- linux网络管理----网络基础
- SCU 4445 Right turn
- disconf-web 分布式配置管理平台
- GeneXus手机开发基础配置
- Git in Powershell saying 'Could not find ssh-agent'
- wampserver -- 解决Exception Exception in module wampmanager.exe at 000F15A0
- python开发_tkinter
- 机器学习中的 precision、recall、accuracy、F1 Score