当前位置: 首页 > news >正文

网站建设需要域名吗?情感链接

网站建设需要域名吗?,情感链接,网站极速备案,企业平台网站建设惭愧&#xff0c;知道该用DP做&#xff0c;但是又翻了参考书才想起来。dp[i]表示以i项为结尾的最大子列。 #include <cstdio> #include <vector>int K, maxx, u, pu, pv; std::vector<int> vec, dp;int main(){scanf("%d", &K);vec.resize(K)…

惭愧,知道该用DP做,但是又翻了参考书才想起来。dp[i]表示以i项为结尾的最大子列。

#include <cstdio>
#include <vector>int K, maxx, u, pu, pv;
std::vector<int> vec, dp;int main(){scanf("%d", &K);vec.resize(K);dp.resize(K);maxx = -1;for(int i = 0; i < K; ++i){scanf("%d", &vec[i]);if(i == 0){dp[0] = vec[0];u = 0;} else{if(dp[i - 1] < 0){dp[i] = vec[i];u = i;} else{dp[i] = vec[i] + dp[i - 1];}}if(dp[i] > maxx){maxx = dp[i];pu = u;pv = i;}}if(maxx == -1){printf("0 %d %d", vec[0], vec[K - 1]);} else{printf("%d %d %d", maxx, vec[pu], vec[pv]);}return 0;
}

题目如下:

Given a sequence of K integers { N1​, N2​, ..., NK​ }. A continuous subsequence is defined to be { Ni​, Ni+1​, ..., Nj​ } where 1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.

Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.

Input Specification:

Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer K (≤10000). The second line contains K numbers, separated by a space.

Output Specification:

For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices i and j (as shown by the sample case). If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.

Sample Input:

10
-10 1 2 3 4 -5 -23 3 7 -21

Sample Output:

10 1 4
http://www.hkea.cn/news/702446/

相关文章:

  • vf建设银行网站谷歌seo排名
  • 如何申请商业服务器武汉seo工厂
  • 祥云平台英文网站微博指数查询入口
  • 公司网站建设准备资料今日重大财经新闻
  • 发布网站后备案免费网站建站页面
  • 浙江建设职业技术学院迎新网站做一个网站要多少钱
  • axure做网站好不好手机百度问一问
  • 开发微信小程序的流程广州seo优化电话
  • 小企业网站建设和管理全能搜
  • 无棣县建设局网站游戏优化大师下载安装
  • 小额贷款 网站模板品牌推广软文
  • 网站建设开发成本天津百度搜索网站排名
  • 做的好的营销型网站有哪些内容外贸网站外链平台
  • 东营网站建设预算价格百度网盘网页版入口官网
  • 网站建设中标公告18款禁用看奶app入口
  • 网站运营人员岗位职责长沙正规seo优化价格
  • cnzz统计代码放在后台网站为什么没显示seo的英文全称是什么
  • 杭州企业网站建设方案广告门
  • 自己免费做网站(二)seo优化公司信
  • 广州外贸b2b网站建设刷钻业务推广网站
  • 做企业网站用什么怎样宣传自己的品牌
  • 濮阳做网站的公司我的百度账号
  • 美食网站开发如何做好网络营销工作
  • 网站建设案例资料今天的新闻内容
  • 台州专业网站建设方案seo软文代写
  • 个人网站 百度推广全球搜索大全
  • 网站消息推送5118素材网站
  • 天津 响应式网站设计企业网站模板免费
  • 网站用花生壳nas做存储百度seo发包工具
  • wordpress cache深圳纯手工seo