链接:

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. [转帖]Linux Shell常用技巧(五)

    Linux Shell常用技巧(五) https://zhuanlan.zhihu.com/p/73451771 1. 变量:在awk中变量无须定义即可使用,变量在赋值时即已经完成了定义.变量的类型可 ...

  2. 分布式架构下,session共享有什么方案么?

    分布式架构下,session共享有什么方案么? 会点代码的大叔 科技领域创作者 分布式架构下的session共享,也可以称作分布式session一致性:关于这个问题,和大家说一说解决方案(如果有其他的 ...

  3. TIM—基本定时器代码

    使用目的:使用TIM定时器让小灯每0.5秒翻转一次亮灭 编程过程: 1-配置时基初始化结构体 2-开启定时器更新中断(即定时时间到了) 3-配置中断优先级 4-使能定时器 5-编写中断服务函数 6-编 ...

  4. asp.net core-7.在Core Mvc中使用Options

    1,添加asp.net core mvc应用程序 2,添加Controllers控制器文件夹,Views视图文件夹 然后在Startup类中ConfigureServices方法中注册一下servic ...

  5. electron窗口相关操作(放大缩小退出,可拖动,可resize等)

    如下是对窗口最大化,最小化等相关操作: import { ipcMain, ipcRenderer, remote } from 'electron' import is from 'electron ...

  6. Windows下Notepad++连接VMWare中的linux,然后无法安装NppFTP

    一.关于Notepad++版本 我的版本是最新版本:Notepad++ v7.7 32bit 版本最好选择32bit的,看别处的说法是官网上有这样的说明: Note that the most of ...

  7. 怎样理解没有this的构造函数

    如果一个构造函数内部没有this, 那可以说这个压根不是构造函数, 因为他并不能返回一个实例对象; function Person(name) { var name = name; }; var li ...

  8. Java BinarySearch

    Java BinarySearch /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternation ...

  9. 定时任务FluentScheduler

    1.Nuget 安装包 2.创建3个不同的任务 public class MyJob : IJob { void IJob.Execute() { Trace.WriteLine("现在时间 ...

  10. Android监听EditText输入字符串,删除指定的字符

    alert_ed = (EditText) a.findViewById(R.id.alert_ed_queue_num); alert_ed.addTextChangedListener(mText ...