链接:

https://vjudge.net/problem/POJ-3186

题意:

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.

思路:

Dp[i, j]表示对于l-r最多能卖多少钱, 对于当前可以卖l,或r, 记录age往下Dfs.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const LL MOD = 20090717;
const int MAXN = 2e3+10; LL Dp[MAXN][MAXN];
int a[MAXN];
int n; LL Dfs(int l, int r, int step)
{
if (Dp[l][r] != -1)
return Dp[l][r];
if (l == r)
{
Dp[l][r] = a[l]*step;
return Dp[l][r];
}
LL val = 0;
val = max(val, a[l]*step+Dfs(l+1, r, step+1));
val = max(val, a[r]*step+Dfs(l, r-1, step+1));
Dp[l][r] = val;
return Dp[l][r];
} int main()
{
scanf("%d", &n);
for (int i = 1;i <= n;i++)
scanf("%d", &a[i]);
memset(Dp, -1, sizeof(Dp));
printf("%lld\n", Dfs(1, n, 1)); return 0;
}

POJ-3186-Treats for the Cows(记忆化搜索)的更多相关文章

  1. POJ 1191 棋盘分割 【DFS记忆化搜索经典】

    题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  2. POJ 1579 Function Run Fun 【记忆化搜索入门】

    题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS   Memory Limit: 10000K Tota ...

  3. poj 3186 Treats for the Cows(区间dp)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  4. POJ 3186 Treats for the Cows (动态规划)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  5. poj 3186 Treats for the Cows(dp)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  6. (中等) POJ 1054 The Troublesome Frog,记忆化搜索。

    Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...

  7. POJ 3249 Test for Job (记忆化搜索)

    Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11830   Accepted: 2814 Des ...

  8. POJ 3186 Treats for the Cows 一个简单DP

    DP[i][j]表示现在开头是i物品,结尾是j物品的最大值,最后扫一遍dp[1][1]-dp[n][n]就可得到答案了 稍微想一下,就可以, #include<iostream> #inc ...

  9. POJ 3186 Treats for the Cows

    简单DP dp[i][j]表示的是i到j这段区间获得的a[i]*(j-i)+... ...+a[j-1]*(n-1)+a[j]*n最大值 那么[i,j]这个区间的最大值肯定是由[i+1,j]与[i,j ...

随机推荐

  1. (六)Cookie 知识点总结 (来自那些年的笔记)

    如果你想要转载话,可不可以不要删掉下面的 作者信息 呀!: 作者:淮左白衣 写于 2018年4月18日18:47:41 来源笔者自己之前学javaWeb的时候,写的笔记 : 目录 如果你想要转载话,可 ...

  2. Django打印出在数据库中执行的语句

    有时我们需要看models操作时对应的SQL语句, 可以用如下方法查看--- 在django project中的settings文件尾部添加如下代码 LOGGING = { 'version': 1, ...

  3. SAS学习笔记40 SAS程序运行过程

    当我们提交运行一个DATA步程序后,具体发生了什么事情. SAS程序与其他程序一样,在运行时都要经过两个阶段:编译(Compilation).执行(Execution) 程序首先经过编译阶段,该阶段主 ...

  4. asp.net core-5.控制台读取json文件

    1,创建控制台应用程序,应用using Microsoft.Extensions.Configuration; 2,新建一个app.json文件 然后修改app.json的属性 3,生成项目,可以看到 ...

  5. 关于arm 的字节对齐

    一.什么是字节对齐,为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这 ...

  6. AtCoder Grand Contest 040 C - Neither AB nor BA

    传送门 好妙的题啊 首先容易想到简单容斥,统计合法方案数可以考虑总方案数减去不合法方案数 那么先考虑如何判断一个串是否合法,但是直接判断好像很不好搞 这时候就需要一些 $magic$ 了,把所有位置下 ...

  7. 从业务流程角度:分析TMS系统各个功能模块

    TMS的主要功能是协调承运商.运营商.货主三种角色人员分工合作共同完成运输任务,并实现对运输任务的跟踪管理.本文将按照业务流程顺序对TMS系统各个功能模块进行分析说明. 一.业务描述 新零售的兴起及& ...

  8. Effective Java 读书笔记(二):对象通用方法

    1 重写equals方法时请遵守通用约定 (1)无需覆盖equals方法的情况 要求独一无二 不要求逻辑相等 超类已经覆盖equals方法,对其子类也适用 一个类是私有的或者是包私有(可以重写后抛出异 ...

  9. ajax获取后台数据出错parsererror

    原因是dataType如果为json,返回的数据是text就会报错.

  10. 1249: 人见人爱A^B

    题目描述 求A^B的最后三位数表示的整数. 说明:A^B的含义是“A的B次方”  输入 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果 ...