英语翻译 Maximum sum
OpenJudge - 1481:Maximum sum
2022 2.10
Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:
给定一组n个整数:A={a1,a2,…,an},我们定义函数d(A)如下:
t1 t2 d(A) = max{ ∑ai + ∑aj | 1 <= s1 <= t1 < s2 <= t2 <= n }i=s1 j=s2
d(A)为两段和的最大值,不相交。
Your task is to calculate d(A).
你的任务是计算d(A).
输入
The input consists of T(<=30) test cases. The number of test cases T is given in the first line of the input.
输入由T(<=30)个测试用例组成。测试用例的数量T在输入的第一行给出。
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.
每个测试用例包含两行。第一行是一个整数n(2<=n<=50000)。第二行包含n个整数:a1,a2.....,(|ai |<=10000)。每个案例后面都有一个空行。
输出
Print exactly one line for each test case. The line should contain the integer d(A).
每个测试用例只打印一行。该行应包含整数d(A)的值。
样例输入
110 1 -1 2 2 3 -3 4 -4 5 -5
样例输出
13
提示
In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer.
Huge input,scanf is recommended.
在样本中,我们选择{2,2,3,-3,4}和{5},然后我们可以得到答案。
投入巨大,建议使用scanf。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[50004],b[50004],c[50004]; //用b[]来储存从左往右的最大子段和
int main() //用c[]来储存从右往左的最大子段和
{int t;scanf("%d",&t); //输入数据较大,推荐使用scanfwhile(t--){memset(a,0,sizeof a); //先将三个数组清空memset(b,0,sizeof b);memset(c,0,sizeof c);int n,ans=-1e9; //答案可能为负数,因此ans要为-1e9scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);b[0]=-1e9; //预处理,保证b[0]不会被取到int sum=0; //当前子段和for(int i=1;i<=n;i++){b[i]=max(b[i-1],sum+a[i]); //状态转移方程sum+=a[i];if(sum<0) sum=0; //如果sum<0,为了保证sum子段和最大} //要重新开始计算(即sum=0)//同理,求从右往左的最大子段和c[n+1]=-1e9; sum=0;for(int i=n;i>0;i--){c[i]=max(c[i+1],sum+a[i]);sum+=a[i];if(sum<0) sum=0;ans=max(ans,b[i]+c[i+1]); //遍历求最大值}printf("%d\n",ans);}return 0;
}
英语翻译 Maximum sum相关推荐
- D28:Maximum sum(最大和,翻译)
原题:OpenJudge - 1481:Maximum sum 翻译: 描述:给定一组n个整数:A={a1,a2,...,an},我们定义函数d(A)如下: t1 t2 d(A) = max{ ∑ai ...
- 各种数学名词的英语翻译
各种数学名词的英语翻译 数学 mathematics, maths(BrE), math(AmE) 公理 axiom 定理 theorem 计算 calculation 运算 operation 证明 ...
- 英语翻译的重点词汇词组
英语翻译重点词汇 fellow countrymen 同胞 militarist军阀 Chinese Communist Party 党组织 the Grand Canal (京杭)大运河 Indus ...
- 人名翻译_考研英语翻译:句子中出现人名怎么办?
之前有同学问:金融考研英语翻译里出现人名需要翻吗?是的,需要.今天金程考研小编就来讲讲考研英语真题中的人名该如何翻译. 01 "约定俗成"的人名翻译 如果是名人,中文翻译的名字通行 ...
- OpenAI数十亿代码训出Codex:能将英语翻译成代码,给四句话就能写个神经网络...
点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 来源:大数据文摘本文约2088字,建议阅读4分钟 本文介绍了Open ...
- python英语翻译-python制作英语翻译小工具
用python爬虫可以制作英语翻译小工具.来看下代码吧- import requests,json #函数封装 def translator(): session=requests.session() ...
- python英语翻译-python制作英语翻译小工具代码实例
这篇文章主要介绍了python制作英语翻译小工具代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 用python爬虫可以制作英语翻译小工具.来 ...
- 计算机英语翻译的典故,中国成语典故英语翻译大全
中国成语典故英语翻译大全 大功告成 The big project finally came off with honors (bring home the bacon; come through w ...
- URAL 1146 Maximum Sum(最大子矩阵的和 DP)
Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...
最新文章
- shell脚本分析mysql慢查询日志(slow log)
- JavaScript 的内部字符编码是 UCS-2 还是 UTF-16
- count(1),count(*),count(主键) 性能对比及辟谣
- 巨人网络305亿并购海外棋牌类游戏公司审核遭暂停
- 1071 Speech Patterns
- 那些想上天的亿万富翁,开启了新的“太空竞赛”
- 微信小程序开发工作流程
- 为什么视频无法播放,视频无法播放的原因是什么
- 计算机组成原理 存储器
- 设计模式-创建者模式篇
- 6个哄自己开心的小技巧
- IPLC专线使用心得,速度惊人!
- B - Learning Languages
- 若依 / RuoYi-Vue 前后端分离,前端部署及注意事项
- Oracle应用之to_char(参数,'FM990.00')函数
- c语言expand函数,编纂expand(s1,s2)
- 西门子200恒压供水梯形图_S7-200 PLC控制的变频调速恒压供水系统设计
- 广告公司销售员怎么找客户 精准客户资源获取方法
- 因为计算机中丢失dui,修复WmpDui.dll
- 页面滚动头部固定 背景色显现