hdu 1003 hdu 1231 最大连续子序列【dp】
2024-10-08 01:27:46
题意自明。可能是真的进步了点,记得刚开始研究这个问题时还想了好长时间,hdu 1231还手推了很长时间,今天重新写干净利落就AC了。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+;
int a[MAXN]; int main()
{
int T,N;
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
scanf("%d",&N);
for(int i=;i<=N;i++){
scanf("%d",&a[i]);
}
int ans=-1e9;
int l=,r=,pos=;
int tot=;
for(int i=;i<=N;i++){
tot+=a[i];
if(tot>ans){
ans=tot;
r=i;
l=pos;
}
if(tot<){
tot=;
pos=i+;
}
}
printf("Case %d:\n%d %d %d\n",cas,ans,l,r);
if(cas!=T)
printf("\n");
}
return ;
}
HDU 1003
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=1e5+;
int a[MAXN];
int N; int main()
{
while(scanf("%d",&N)==,N)
{
int cnt=;
for(int i=;i<=N;i++){
scanf("%d",&a[i]);
if(a[i]<) cnt++;
}
int ans=-1e9;
int l=,r=,pos=;
int tot=;
for(int i=;i<=N;i++){
tot+=a[i];
if(tot>ans){
ans=tot;
r=i;
l=pos;
}
if(tot<){
tot=;
pos=i+;
}
}
if(cnt==N){
ans=;
printf("%d %d %d\n",ans,a[],a[N]);
}else{
printf("%d %d %d\n",ans,a[l],a[r]);
}
}
return ;
}
HDU 1231
最新文章
- array&#39;s filter
- 一个iOS 框架介绍:MKNetworkKit
- 【读书笔记】iOS-Tagged Pointer对象-注意事项
- peak num
- HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法
- 常用icon以及color颜色RGB值和对应颜色效果图
- iOS摄像头和相册-UIImagePickerController-浅析
- CSAPP(深入理解计算机系统)读后感
- linux-kernel/CodingStyle
- Oracle 11g RAC database on ASM, ACFS or OCFS2
- Hive ERROR: Out of memory due to hash maps used in map-side aggregation
- .NET 微服务和Docker容器
- linux命令和awk
- Linux文档的压缩与打包
- 并行设计模式(二)-- Master-Worker模式
- Android 纵向跑马灯滚动效果
- 数据结构(六)查找---平衡二叉树(ASL)
- u3d加载加密和未加密
- 前端图片压缩(纯js)
- Dinic算法----最大流常用算法之一