BNUOJ 5227 Max Sum
2024-08-30 05:44:55
Max Sum
Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 1003
64-bit integer IO format: %I64d Java class name: Main
64-bit integer IO format: %I64d Java class name: Main
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
Sample Output
Case 1:
14 1 4 Case 2:
7 1 6 解题:dp入门题!弱菜的成长之路啊!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
int dp[],num[];
int main(){
int kase,i,index,ans,n,k = ;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
for(i = ; i <= n; i++)
scanf("%d",dp+i);
num[] = ;
ans = dp[index = ];
for(i = ; i <= n; i++){
if(dp[i] <= dp[i-]+dp[i]){
dp[i] = dp[i-]+dp[i];
num[i] = num[i-]+;
}else num[i] = ;
if(ans < dp[i]) ans = dp[index = i];
}
printf("Case %d:\n",k++);
printf("%d %d %d\n",ans,index-num[index],index);
if(kase) putchar('\n');
}
return ;
}
最新文章
- 阿里云推送SDK在某些机型(某米为主)下崩溃问题的解决方法
- 初学RunLoop
- LUA类
- 深入浅出Mybatis系列(七)---mapper映射文件配置之insert、update、delete
- ASP.NET DAY1
- 通过PowerShell发送TCP请求
- submit回车提交影响
- 【windows核心编程】一个API拦截的例子
- bnuoj 4187 GCC (数论)
- hibernate实体的几种状态:
- 什么是CTS、CLS和CLR
- cocos2dx3.2 异步载入和动态载入
- [WPF]不规则窗体的实现
- java线程池ThreadPool
- linux_Nginx日志
- Python第三方库的安装方法总结
- [转]使用jenkins实现持续集成
- IIS异常:CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\.。。”--“拒绝访问
- 51Nod1123 X^A Mod B 数论 中国剩余定理 原根 BSGS
- function前加运算符实现立即执行函数