[USACO11JAN]利润Profits
题目描述
The cows have opened a new business, and Farmer John wants to see how well they are doing. The business has been running for N (1 <= N <= 100,000) days, and every day i the cows recorded their net profit P_i (-1,000 <= P_i <= 1,000).
Farmer John wants to find the largest total profit that the cows have made during any consecutive time period. (Note that a consecutive time period can range in length from one day through N days.) Help him by writing a program to calculate the largest sum of consecutive profits.
牛们开了家新公司,这家公司已经运作了N天,财务报表显示第i天获得的利润为Pi , 有些天的利润可能是个负数。约翰想给奶牛公司写个新闻报道,以吹嘘她们的业绩。于是他 想知道,这家公司在哪一段连续的日子里,利润总和是最大的。
输入输出格式
输入格式:
Line 1: A single integer: N
- Lines 2..N+1: Line i+1 contains a single integer: P_i
输出格式:
- Line 1: A single integer representing the value of the maximum sum of profits for any consecutive time period.
输入输出样例
7
-3
4
9
-2
-5
8
-3
14
说明
The maximum sum is obtained by taking the sum from the second through the sixth number (4, 9, -2, -5, 8) => 14.
簡單動規。(因為方程沒法應付全負的情況,加了個l特判)
代碼實現:
#include<cstdio>
#include<iostream>
using namespace std;
int n,a,b,c,l=-,f[][];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a);
b=i%;c=(b+)%;l=max(l,a);
f[b][]=max(f[c][],f[c][]);
f[b][]=max(f[c][]+a,a);
}
if(l>=) printf("%d\n",max(f[n%][],f[n%][]));
else printf("%d\n",l);
return ;
}
還記得某種數列問題嗎?
[USACO11JAN]利润Profits的更多相关文章
- 洛谷 P3009 [USACO11JAN]利润Profits
嗯... 题目链接:https://www.luogu.org/problemnew/show/P3009 这是DP的另一个功能,求最大子段和(最大子段和模板:https://www.luogu.or ...
- USACO 利润Profits
洛谷P3009 [USACO11JAN]利润Profits 题解 https://www.luogu.org/problemnew/solution/P3009 JDOJ 2727: USACO 2 ...
- 【 USACO11JAN】 利润 【洛谷P3009】
P3009 [USACO11JAN]利润Profits 题目描述 The cows have opened a new business, and Farmer John wants to see h ...
- 从键盘输入当月利润I,求应发放奖金总数?
企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%:20万到40万之间时 ...
- Qt带来的是更加低廉的开发成本和学习成本,对于很多小公司而言,这种优势足以让他们获得更大的利润空间 good
不能单纯从技术上来看待这个问题,Qt本来是小众的开发平台,个人认为,它的出现只是解决特性场景的特定问题,Qt带来的是更加低廉的开发成本和学习成本,对于很多小公司而言,这种优势足以让他们获得更大的利润空 ...
- ecshop 后台添加 成本价 利润
ecshop后台admin中的商品操作php文件,goods.php替换为下面的代码, 还要在数据库商品本店售价后门添加 cost 字段 为 商品成本价 ecs_goods表中添加 cost ...
- Algorithm --> 投资组和求最大利润
投资组和求最大利润 题目: 投资人出资一笔费用mount,投资给不同的公司(A,B,C....),求最大获取利润? 例如:投资400百万,给出两家公司A和B: 1.如果投资一百万给A公司,投资3百万给 ...
- [USACO11JAN]大陆议会The Continental Cowngress_2-sat
[USACO11JAN]大陆议会The Continental Cowngress_2-sat 题意: 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会. 议会以“每头 ...
- 『战略游戏 最大利润 树形DP』
通过两道简单的例题,我们来重新认识树形DP. 战略游戏(luoguP1026) Description Bob喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的办法.现在他有个问题.他要 ...
随机推荐
- Problem A CodeForces 556A
Description Andrewid the Android is a galaxy-famous detective. In his free time he likes to think ab ...
- [转] Android资源管理框架(Asset Manager)简要介绍和学习计划
转自:http://blog.csdn.net/luoshengyang/article/details/8738877 Android应用程序主要由两部分内容组成:代码和资源.资源主要就是指那些与U ...
- Python网络编程03----Python3.*中socketserver
socketserver(在Python2.*中的是SocketServer模块)是标准库中一个高级别的模块.用于简化网络客户与服务器的实现(在前面使用socket的过程中,我们先设置了socket的 ...
- 利用烧鹅制作简单BadUSB,插谁谁怀孕
所用硬件设备为烧鹅,烧鹅是RadioWar基于Teensy++ 2.0 AT90USB1286芯片设计的USB Rubber Ducky类开发板. 使用veil编码meterpreter生成paylo ...
- 您不能在64-位可执行文件上设置DEP属性?
我是为dllhost.exe设置DEP时遇到了同样的情况.你需要选择64位系统对应的程序.64位系统:C:\Windows\SysWOW64\dllhost.exe32位系统:C:\Windows\S ...
- SSO单点登录
登录持久化机制:Cookies&&Session Cookie:是将信息存储到客户端,所有的信息不安全,都会对信息进行加密,cookies中会存储当前会话的唯一标识,即SessionI ...
- AmazeUI HTML元素
按钮Button am-btn-xx(default.primary.secondary.success.warning.danger.link) am-radius 圆角按钮 am-round 椭圆 ...
- android:windowSoftInputMode及其他部分属性用法
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 今天我们来讲讲android:windoSoftInputMode的用法,许多同学会为软键盘的弹出. ...
- Quirks模式是什么?
什么是DOCTYPE: DOCTYPE,或者称为 Document Type Declaration(文档类型声明,缩写 DTD).通常情况下,DOCTYPE 位于一个 HTML 文档的最前面的 位置 ...
- 【ajax】xhr
jQuery xhr: function() { return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP&quo ...