POJ 题目2796 Feel Good(动态规划)

Feel Good

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 11041   Accepted: 3020
Case Time Limit: 1000MS   Special Judge

Description

Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people‘s memories about some period of life.

A new idea Bill has recently developed assigns a non-negative integer value to each day of human life.

Bill calls this value the emotional value of the day. The greater the emotional value is, the better the daywas. Bill suggests that the value of some period of human life is proportional to the sum of the emotional values of the days in the given period, multiplied
by the smallest emotional value of the day in it. This schema reflects that good on average period can be greatly spoiled by one very bad day.

Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.

Input

The first line of the input contains n - the number of days of Bill‘s life he is planning to investigate(1 <= n <= 100 000). The rest of the file contains n integer numbers a1, a2, ... an ranging from 0 to 106 - the emotional values of the days.
Numbers are separated by spaces and/or line breaks.

Output

Print the greatest value of some period of Bill‘s life in the first line. And on the second line print two numbers l and r such that the period from l-th to r-th day of Bill‘s life(inclusive) has the greatest possible value. If there are multiple periods with
the greatest possible value,then print any one of them.

Sample Input

6
3 1 6 4 5 2

Sample Output

60
3 5

Source

Northeastern Europe 2005

题目大意:给你n个数的数组arr[n]。要你找到一个L和R是的。(arr[L]+.....+arr[R])*arr[k]的值最大。arr[k]为L->R的数的最小值。

分析:跟杭电oj1506差不多

ac代码

#include<stdio.h>
#include<string.h>
int l[100100],r[100100];
__int64 a[100100],sum[100100];
int main()
{
	int n;
	scanf("%d",&n);

	int i;
	sum[0]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		sum[i]=sum[i-1]+a[i];
		l[i]=r[i]=i;
	}
	*for(i=1;i<=n;i++)
	{
		while(l[i]>1&&a[l[i]-1]>=a[i])
		{
			l[i]=l[l[i]-1];
		}
	}
	for(i=n;i>=1;i--)
	{
		while(r[i]<n&&a[r[i]+1]>=a[i])
		{
			r[i]=r[r[i]+1];
		}
	}
	__int64 ans=-1;
	int x,y;
	for(i=1;i<=n;i++)
	{
		if((sum[r[i]]-sum[l[i]-1])*a[i]>ans)
		{
			ans=(sum[r[i]]-sum[l[i]-1])*a[i];
			x=l[i];
			y=r[i];
		}
	}
	printf("%I64d\n%d %d\n",ans,x,y);

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-09-30 19:33:50

POJ 题目2796 Feel Good(动态规划)的相关文章

[POJ 1787]Charlie&#39;s Change (动态规划)

题目链接:http://poj.org/problem?id=1787 题意:有4种货币分别是1元,5元,10元,20元.现在告诉你这四种货币分别有多少个,问你正好凑出P元钱最多可以用多少货币.每种货币要用多少钱. 据说此题有完全背包的写法.. 我是按照多重背包写的,速度也不是很慢. 然后记录了下前驱. 刚开始全都写挫了..虽然现在也很挫.. 凑合着看吧 -- 1 #include <cstdio> 2 #include <algorithm> 3 #include <cst

POJ题目分类推荐 (很好很有层次感)

著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

POJ 1160 Post Office (动态规划)

Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15412   Accepted: 8351 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each villa

【转】POJ题目分类

初级:基本算法:枚举:1753 2965贪心:1328 2109 2586构造:3295模拟:1068 2632 1573 2993 2996图:最短路径:1860 3259 1062 2253 1125 2240最小生成树:1789 2485 1258 3026拓扑排序:1094二分图的最大匹配:3041 3020最大流的增广路算法:1459 3436数据结构:串:1035 3080 1936排序:2388 2299哈希表和二分查找等高效查找法:3349 3274 2151 1840 2002

POJ 1018 Communication System (动态规划)

Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22500   Accepted: 8008 Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices.

POJ题目(转)

http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (

POJ 1185 炮兵阵地(动态规划)

炮兵阵地 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19152   Accepted: 7417 Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表示),如下图.在每一格平原地形上最多可以布置一支炮兵部队(山地上不能够部署炮兵部队):一支炮兵部队在地图上的攻击

Poj 题目分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea