[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喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的办法.现在他有个问题.他要 ...
随机推荐
- JavaScript 数组方法和属性
一. 数组对象的操作方法 1. 数组的创建 2.prototype属性 返回对象原型的引用,prototype属性时object共有的. objectName.prototype,其中objectNa ...
- UML学习入门就这一篇文章
1.1 UML基础知识扫盲 UML这三个字母的全称是Unified Modeling Language,直接翻译就是统一建模语言,简单地说就是一种有特殊用途的语言. 你可能会问:这明明是一种图形,为什 ...
- [转]C++运算优先级列表
From:http://en.cppreference.com/w/cpp/language/operator_precedence Precedence Operator Description A ...
- 同是url参数传进来的值,String类型就用getAttribute获取不到,只能用getParameter获取,而int就两个都可以这是为什么?
这是因为int的属性是id,这是在被放到modeldriver中的user所具有的属性,传递过来的参数如果和user的属性重名,struts2的有类似beanutil之类的工具会自动封装参数,这时候用 ...
- JS 代理模式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 转:HashMap深度解析(一)
HashMap哈希码hashCodeequals 本文来自:高爽|Coder,原文地址:http://blog.csdn.net/ghsau/article/details/16843543,转载 ...
- Listview之优化BaseAdapter中的getView中的contentView
BaseAdapter中getView中改动的地方: @Override public View getView(int position, View contentView, ViewGroup a ...
- hdoj-2033
A+B系列: #include "stdio.h"int main(){ int a[3],b[3],c[3],i,n,j,flag; while(~scanf("%d& ...
- 用javascript正则表达式来格式化金额
<html><head><script> function a() { var amount = "-22334.334455"; //if(/ ...
- 怎么用sql语句查看某个字段值是否是唯一的
select count(*) from table group by zd having count(*)>1 这是不唯一的过滤出来的语句