POJ3186Treats for the Cows题解动态规划DP
来源:互联网 发布:手游开黑语音软件 编辑:程序博客网 时间:2024/05/25 18:11
Treats for the Cows
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2686 Accepted: 1280
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 first treat is sold on day 1 and has age a=1. Each subsequent day increases the age by 1.
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.
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)
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
513152
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.
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.
Source
USACO 2006 February Gold & Silver
状态:
d[i][j]表示第i个到第j个的最大值
状态转移方程:
d[i][j]=max(d[i+1][j]+a[i]*(n+i-j),d[i][j-1]+a[j]*(n+i-j))
为了满足无后效性i逆序循环
代码:
- POJ3186Treats for the Cows题解动态规划DP
- poj3186Treats for the Cows(区间DP)
- POJ3186Treats for the Cows
- POJ-3186-Treats for the Cows-动态规划DP
- POJ3666Making the Grade题解动态规划DP
- O - Treats for the Cows POJ 3186 ( 动态规划+区间 )
- poj 3186 Treats for the Cows 动态规划
- 动态规划训练20 [Treats for the Cows POJ
- 【动态规划】[luoguP2858 USACO06FEB]奶牛零食Treats for the Cows
- I'm Attacking the Darkness!题解动态规划DP
- POJ3666 Making the Grade题解-动态规划dp
- Bookshelf题解动态规划DP
- POJ2353Ministry题解动态规划DP
- POJ1260Pearls题解动态规划DP
- HDU2845Beans题解动态规划DP
- POJ3356AGTC题解动态规划DP
- POJ1745Divisibility题解动态规划DP
- HDU3449Consumer题解动态规划DP
- MTK LCD 和 CAMERA 相关问题
- Hsql2.0 入门
- ..............................
- NetBeans 时事通讯(刊号 # 113 - Aug 11, 2010)
- 理解与应用LDAP服务器
- POJ3186Treats for the Cows题解动态规划DP
- 我是处女座 男
- 究竟怎么才能提高网络管理的实践操作能力呢?
- c# 修改系统日期格式
- ProduceAndConsume
- LINQ基本子句介绍
- 回归
- Sql处理两条相邻的语句(比较大小)
- javascript的验证和上一文有关