链接:

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. JDBC 注册驱动,获取连接

    jdbc 动力节点视频教程 JDBC编程六步 1.注册驱动(作用:告诉Java程序,即将要连接的是哪个品牌的数据库) 2.获取连接 (表示JVM进程和数据库进程之间的通道打开了,属于进程间的通信,重量 ...

  2. springboot用controller跳转html页面

    之前SSM框架,里面有webapps文件夹,用来存放前端页面和各种前端资源,现在SpringBoot中没有webapps文件夹,springboot结构如下: 第一.resourses下文件夹publ ...

  3. 【C++札记】引用

    介绍 引用是C++中特有的语法,在C语言中不存在. 本质上引用(reference)就是指针,在类型名后面加上一个&号就是引用类型. 1.指针与引用的定义进行比较 指针定义: 引用定义: in ...

  4. TZOJ数据结构实验:左叶子之和

    int sumOfLeftLeaves(struct TreeNode* root) { if (root == NULL) { ; }//递归结束条件 if (root->left & ...

  5. qt-博客

    将QQ中的图文聊天内容显示到Qt界面: http://www.qter.org/portal.php?mod=view&aid=12

  6. Destination高级特性

    一.组合队列 Composite Destinations 组合队列允许用一个虚拟的destination代表多个destinations.这样就可以通过composite destinations在 ...

  7. (十三)Activitivi5之流程控制网关:并行

    一.概念 所谓排他网关 顾名思义 执行到该网关,会有多条线路同时并行执行,当都执行完才继续执行后面的: 二. 案例 此时当“学生请假”任务节点完成之后,如下图此时有两个任务,必须等到两个任务都完成才会 ...

  8. springboot启动流程(十)springboot自动配置机制

    所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 正文 在第七篇文章中我们了解到,refresh过程将会调用ConfigurationClass ...

  9. Cascader 级联选择器无法赋值

    问题: html: <el-cascader v-model="addform.qxvalue" :options="options" :props=&q ...

  10. (详细)JAVA使用JDBC连接MySQL数据库(3)-代码部分

    欢迎任何形式的转载,但请务必注明出处. 本节主要内容 项目建立 数据库连接 数据库操作 主函数 点击进入推荐博客(必看) 一.项目建立 如图所示:新建Java Project.Package.Clas ...