[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喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的办法.现在他有个问题.他要 ...
随机推荐
- seajs 使用 jquery插件
define(function(require,exports,moudles){ return function(jquery){ (function($) { $.fn.pri= function ...
- POJ 2992 求组合数的因子个数
求C(n,k)的因子个数 C(n,k) = (n*(n-1)*...*(n-k+1))/(1*2*...*k) = p1^k1 * p2^k2 * ... * pt^kt 这里只要计算出分子中素数因子 ...
- 一个完整的ansible实施目录示例
当前目录:
- Android USB Connections Explained: MTP, PTP, and USB Mass Storage
Android USB Connections Explained: MTP, PTP, and USB Mass Storage Older Android devices support USB ...
- Java 嵌套作用域
在C/C++中,当一个块处于另一个块作用域内的时候,内层定义的变量会把外层的变量隐藏, 遵循所谓的就近原则. 在Java中,在内层定义与外层同名的变量是禁止的! 如下: int i = 0; for( ...
- 【Oracle XE系列之三】使用OMF方式手工创建Oracle XE数据库
环境:win10_X64_Pro 1.创建数据库实例,实例名为PF C:\oraclexe\app\oracle\product\11.2.0\server\bin>oradim -new -s ...
- EnterpriseLibrary4 自己封装程序集实现log打印
注意:1)要引用响应的程序集,必须是41的 2)配置文件 using Microsoft.Practices.EnterpriseLibrary.Common.Configura ...
- HDU5772 (最小割)
Problem String problem (HDU5772) 题目大意 给定一个由数字组成的字符串(n<=100),挑选出一些字符组成一个新的字符串. 字符串的价值: sigma w[id( ...
- HDU 5086
http://acm.hdu.edu.cn/showproblem.php?pid=5086 求所有连续区间的数字和 本质是一个乘法原理,当前位置的数字出现次数=这个数之前的数字个数*这个数之后的数字 ...
- C# 控件聚焦
/********************************************************************** * C# 控件聚焦 * 说明: * 做界面经常需要将ta ...