POJ-3186_Treats for the Cows
Treats for the Cows
Time Limit: 1000MS Memory Limit: 65536K
Description
FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time.
The treats are interesting for many reasons:
The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ can retrieve one treat from either end of his stash of treats.
Like fine wines and delicious cheeses, the treats improve with age and command greater prices.
The treats are not uniform: some are better and have higher intrinsic value. Treat i has value v(i) (1 <= v(i) <= 1000).
Cows pay more for treats that have aged longer: a cow will pay v(i)*a for a treat of age a.
Given the values v(i) of each of the treats lined up in order of the index i in their box, what is the greatest value FJ can receive for them if he orders their sale optimally?
The first treat is sold on day 1 and has age a=1. Each subsequent day increases the age by 1.
Input
Line 1: A single integer, N
Lines 2..N+1: Line i+1 contains the value of treat v(i)
Output
Line 1: The maximum revenue FJ can achieve by selling the treats
Sample Input
5
1
3
1
5
2
Sample Output
43
Hint
Explanation of the sample:
Five treats. On the first day FJ can sell either treat #1 (value 1) or treat #5 (value 2).
FJ sells the treats (values 1, 3, 1, 5, 2) in the following order of indices: 1, 5, 2, 3, 4, making 1x1 + 2x2 + 3x3 + 4x1 + 5x5 = 43.
题意:给予一个数组,每次可以取前面的或者后面的,第k次取的v[i]价值为v[i]*k,问总价值最大是多少。
题解:一个区间DP题目,每一次取的时候可以由d[i+1][j]或者d[i][j-1]转移而来。
转移方程:dp[i][j]=max(dp[i+1][j]+p[i]*(n+i-j),dp[i][j-1]+p[j]*(n+i-j));  其中n-(j-i)是第几次取。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 2050;
int dp[maxn][maxn];
int main()
{
    int n,v[maxn],i,j;
    memset(dp,0,sizeof(dp));
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        {
            scanf("%d",&p[i]);
            dp[i][i]=p[i];
        }
    for(i=n;i>=1;i--)
        for(j=i;j<=n;j++)
            dp[i][j] = max(dp[i+1][j]+v[i]*(n-(j-i)),dp[i][j-1]+v[j]*(n-(j-i)));
    printf("%d\n",dp[1][n]);
    return 0;
}
												
											POJ-3186_Treats for the Cows的更多相关文章
- POJ 2387 Til the Cows Come Home (图论,最短路径)
		
POJ 2387 Til the Cows Come Home (图论,最短路径) Description Bessie is out in the field and wants to get ba ...
 - POJ.2387 Til the Cows Come Home (SPFA)
		
POJ.2387 Til the Cows Come Home (SPFA) 题意分析 首先给出T和N,T代表边的数量,N代表图中点的数量 图中边是双向边,并不清楚是否有重边,我按有重边写的. 直接跑 ...
 - POJ 2387 Til the Cows Come Home
		
题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K ...
 - POJ 2387 Til the Cows Come Home(模板——Dijkstra算法)
		
题目连接: http://poj.org/problem?id=2387 Description Bessie is out in the field and wants to get back to ...
 - POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
		
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
 - 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
		
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33015 Accepted ...
 - POJ 2387  Til the Cows Come Home (最短路 dijkstra)
		
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...
 - (简单) POJ 2387 Til the Cows Come Home,Dijkstra。
		
Description Bessie is out in the field and wants to get back to the barn to get as much sleep as pos ...
 - POJ 2387 Til the Cows Come Home 【最短路SPFA】
		
Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to g ...
 - POJ 2456: Aggressive cows(二分,贪心)
		
Aggressive cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20485 Accepted: 9719 ...
 
随机推荐
- Echarts 的简单使用
			
http://echarts.baidu.com/index.html 直接用script引入从官网下载的echarts.js文件 官网的文件有几种版本的,按需下载即可,注意精简版的只显示折线.圆柱等 ...
 - 20190828 [ Night ] - 弋
			
半集训可还行…… 半集训第一次模拟 考试过程 好像是上回的同套题. ××内个$\text{english}$真毒瘤 T1 什么玩意? $chinese$? 前面两句背景是个? 需要$\Theta(1) ...
 - DynamicDataDisplay 双击获取坐标
			
近日由于项目需要,学习了DynamicDataDisplay实现动态曲线图,网上的资料基本上够用了,就是双击获得数据点没能找到资料,只好下载了DynamicDataDisplay的源码来学习.总结共享 ...
 - Windows下Git的下载、安装、设置用户名和邮箱、创建版本库等
			
Git官网:https://git-scm.com/ 一.Git下载 官网首页下载,当前最新版本:2.24.1 本人下载的是Git for Windows版本:Git-2.24.1.2-64-bit. ...
 - LintCode_41 最大子数组
			
题目 给定一个整数数组,找到一个具有最大和的子数组,返回其最大和. 注意事项 子数组最少包含一个数 样例 给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2,1] ...
 - 【洛谷】P1880 石子合并
			
P1880 石子合并 题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计 ...
 - 微信小程序制作选项卡
			
wxml: <view class="tab"><view class="tab-title" bindtap="tabFun&qu ...
 - Python3.7.4入门-5输入输出
			
5 输入输出 5.1 格式化字符串字面值 在字符串的开始引号或三引号之前加上一个 f 或 F .在此字符串中,你可以在 { 和 } 字符之间写可以引用的变量或字面值的 Python 表达式. > ...
 - SVN经常使用操作
			
版权声明:本文为博主原创文章.转载请注明出处. https://blog.csdn.net/Jerome_s/article/details/27950055 Subversion(简称svn)安装 ...
 - C++通配符
			
#include<iostream>using namespace std;bool PathernMatch(char *pat, char *str){ char *s = NULL; ...