HDU1003 HDU1231

题意自明。可能是真的进步了点,记得刚开始研究这个问题时还想了好长时间,hdu 1231还手推了很长时间,今天重新写干净利落就AC了。

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<algorithm>
  5. using namespace std;
  6. const int MAXN=1e5+;
  7. int a[MAXN];
  8.  
  9. int main()
  10. {
  11. int T,N;
  12. scanf("%d",&T);
  13. for(int cas=;cas<=T;cas++)
  14. {
  15. scanf("%d",&N);
  16. for(int i=;i<=N;i++){
  17. scanf("%d",&a[i]);
  18. }
  19. int ans=-1e9;
  20. int l=,r=,pos=;
  21. int tot=;
  22. for(int i=;i<=N;i++){
  23. tot+=a[i];
  24. if(tot>ans){
  25. ans=tot;
  26. r=i;
  27. l=pos;
  28. }
  29. if(tot<){
  30. tot=;
  31. pos=i+;
  32. }
  33. }
  34. printf("Case %d:\n%d %d %d\n",cas,ans,l,r);
  35. if(cas!=T)
  36. printf("\n");
  37. }
  38. return ;
  39. }

HDU 1003

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<algorithm>
  5. using namespace std;
  6. const int MAXN=1e5+;
  7. int a[MAXN];
  8. int N;
  9.  
  10. int main()
  11. {
  12. while(scanf("%d",&N)==,N)
  13. {
  14. int cnt=;
  15. for(int i=;i<=N;i++){
  16. scanf("%d",&a[i]);
  17. if(a[i]<) cnt++;
  18. }
  19. int ans=-1e9;
  20. int l=,r=,pos=;
  21. int tot=;
  22. for(int i=;i<=N;i++){
  23. tot+=a[i];
  24. if(tot>ans){
  25. ans=tot;
  26. r=i;
  27. l=pos;
  28. }
  29. if(tot<){
  30. tot=;
  31. pos=i+;
  32. }
  33. }
  34. if(cnt==N){
  35. ans=;
  36. printf("%d %d %d\n",ans,a[],a[N]);
  37. }else{
  38. printf("%d %d %d\n",ans,a[l],a[r]);
  39. }
  40. }
  41. return ;
  42. }

HDU 1231

hdu 1003 hdu 1231 最大连续子序列【dp】的更多相关文章

  1. HDU 1231.最大连续子序列-dp+位置标记

    最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  2. HDU 1003 Max Sum && HDU 1231 最大连续子序列 (DP)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  3. ACM_HDU 1231 最大连续子序列 (dp)_代码分析

    Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i < ...

  4. HDU 1231 最大连续子序列 --- 入门DP

    HDU 1231 题目大意以及解题思路见: HDU 1003题解,此题和HDU 1003只是记录的信息不同,处理完全相同. /* HDU 1231 最大连续子序列 --- 入门DP */ #inclu ...

  5. 【ACM】 1231 最大连续子序列

    [1231 最大连续子序列 ** Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...

  6. DP专题训练之HDU 1231 最大连续子序列

    Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j < ...

  7. HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)

    C - 最大连续子序列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  8. HDU 1231 最大连续子序列:水dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231 题意: 给你一个整数序列,求连续子序列元素之和最大,并输出该序列的首尾元素(若不唯一,输出首坐标 ...

  9. HDU 1231——最大连续子序列(DP)

    最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

随机推荐

  1. Wsgi研究

    //转载自http://blog.kenshinx.me/blog/wsgi-research/ wsgi是一个搞web开发的pythoner必须了解的内容,之前也零散的看过一些文章,但总感觉好多概念 ...

  2. laravel-admin 报错 Disk [admin] not configured, please add a disk config in `config/filesystems.php`.

    在config/filesystems.php中添加: 'disks' => [ 'local' => [        'driver' => 'local',        'r ...

  3. mysql_example

    package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysq ...

  4. nginx 限制ip的请求频率

    需要注意,这个很容易误伤 还需要结合别的办法进行共同配置 总是有人很清闲的扫我的网站 ,所以要限制一下了 先来看看没有限制的时候,并发10 100次 服务器一直在正常响应  限制一下,之后再测试一下 ...

  5. php百度地图计算两地现实距离

    请自行到百度地图官网申请您的ak <!--前端获取手机经纬度的代码--> <!--<!DOCTYPE html>--> <!--<html lang=& ...

  6. vue+vant ui+高德地图的选址组件

    首先在index.html引入高德地图的js <script src="https://webapi.amap.com/maps?v=1.4.14&key=你的key" ...

  7. python 全局种子与局部种子

  8. Leetcode653.Two Sum IV - Input is a BST两数之和4-输入BST

    给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true. struct TreeNode { int val; struct TreeNode * ...

  9. fileinput URL携带参数的问题,uploadExtraData,Bootstrap

    因为无法在URL中执行其他代码,通过阅读文档可知可以由uploadExtraData参数携带数据.于是在这里携带,如果uploadExtraData 无法接收到数据,一般是格式有误, 先尝试这个简单的 ...

  10. RegExp实例方法和字符串的模式匹配方法的总结

    RegExp实例方法 ECMAScript通过RegExp类型来支持正则表达式,创建正则表达式有两种方式: //使用字面量形式定义正则表达式 var pattern1 = /[bc]at/i //使用 ...