POJ-3186-Treats for the Cows(记忆化搜索)
链接:
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(记忆化搜索)的更多相关文章
- POJ 1191 棋盘分割 【DFS记忆化搜索经典】
		
题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submission ...
 - POJ 1579 Function Run Fun 【记忆化搜索入门】
		
题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Tota ...
 - 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 ...
 - POJ 3186 Treats for the Cows (动态规划)
		
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
 - 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 ...
 - (中等) POJ 1054 The Troublesome Frog,记忆化搜索。
		
Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a we ...
 - POJ 3249 Test for Job (记忆化搜索)
		
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 11830 Accepted: 2814 Des ...
 - POJ 3186 Treats for the Cows  一个简单DP
		
DP[i][j]表示现在开头是i物品,结尾是j物品的最大值,最后扫一遍dp[1][1]-dp[n][n]就可得到答案了 稍微想一下,就可以, #include<iostream> #inc ...
 - 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 ...
 
随机推荐
- java23种设计模式之八: 工厂方法模式
			
定义: 定义一个创建产品对象的工厂接口,将产品对象的实际创建工作推迟到具体子工厂类当中.这满足创建型模式中所要求的“创建与使用相分离”的特点. 我们把被创建的对象称为“产品”,把创建产品的对象称为“工 ...
 - 【Scratch】它跟Mindstorms,有什么区别?
			
第197篇文章 老丁的课程 在正式开始这套课程之前,依照老丁的习惯,还是要给大家白话下东西,该怎么学? 本节课,来讲讲我对于学习这个软件(包括和EV3配合起来)的一些看法.同时,也给小朋友们一些编程学 ...
 - c++学习总结(一)------类结构学习
			
基类的构造函数并没有被派生类继承 析构函数和拷贝赋值操作符同样也没有 类的设计者通过把成员函数声明为 const 以表明它们不修改类对象 把一个修改类数据成员的函数声明为 const 是非法的 (51 ...
 - Mac电脑配置相关及软件工具安装推荐
			
iTerm2(https://www.iterm2.com/) 终端工具 Alfred(http://xclient.info/s/alfred.html) 快速启动器 WebStorm.VSCode ...
 - MogileFS表说明
			
MogileFS大致的表说明如下 checksum:用来存放文件的校验和class:文件分类定义device:主机上的可用设备定义,包括设备可用空间,使用的权重等信息domain:域定义信息file: ...
 - 根据xsd文件生成对应的C#类,然后创建对应的xml文件
			
首先用xsd文件生产对应的C#类,这个VS已经自带此工单,方法如下: 1. 打开交叉命令行工具 2. 输入如下指令 xsd d:\123.xsd /c /language:C# /outputdir: ...
 - vue elment table根据返回值修改样式
			
今天在写vue项目的时候,查询出的数据库的数据想根据条件修改显示.查询资料有一个 :formatter,可以实现这个效果,废话不多说,这个是我的例子: <el-table-column prop ...
 - [NOIP2018模拟赛10.23]发呆报告
			
闲扯 考场看了眼题目感觉很难,一个小时敲完了所有暴力...嗯然后就在那里发呆什么事也没做 T3考场上把数据结构想了个遍都不会完成1操作,现在看这种思路其实之前也接触过... 比较玄学的一件事情就是T1 ...
 - 手把手教你如何用java8新特性将List中按指定属性排序,过滤重复数据
			
在java中常常会遇到这样一个问题,在实际应用中,总会碰到对List排序并过滤重复的问题,如果List中放的只是简单的String类型过滤so easy,但是实际应用中并不会这么easy,往往List ...
 - 获取select标签的自定义属性
			
$("#ddlUsers").find("option:selected").attr("fullstr"); fullstr就是自定义属性 ...