https://www.luogu.org/problem/show?pid=3089

题目描述

In an ill-conceived attempt to enhance the mobility of his prize cow Bessie, Farmer John has attached a pogo stick to each of Bessie's legs. Bessie can now hop around quickly throughout the farm, but she has not yet learned how to slow down.

To help train Bessie to hop with greater control, Farmer John sets up a practice course for her along a straight one-dimensional path across his farm. At various distinct positions on the path, he places N targets on which Bessie should try to land (1 <= N <= 1000). Target i is located at position x(i), and is worth p(i) points if Bessie lands on it. Bessie starts at the location of any target of her choosing and is allowed to move in only one direction, hopping from target to target. Each hop must cover at least as much distance as the previous hop, and must land on a target.

Bessie receives credit for every target she touches (including the initial target on which she starts). Please compute the maximum number of points she can obtain.

FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度。

FJ觉得让贝西在一条直线的一维线路上进行练习,他在不同的目标点放置了N (1 <= N <= 1000)个目标点,目标点i在目标点x(i),该点得分为p(i)。贝西开始时可以选择站在一个目标点上,只允许朝一个方向跳跃,从一目标点跳到另外一个目标点,每次跳跃的距离至少和上一次跳跃的距离相等,并且必须跳到一个目标点。

每跳到一个目标点,贝西可以拿到该点的得分,请计算他的最大可能得分。

输入输出格式

输入格式:

  • Line 1: The integer N.

  • Lines 2..1+N: Line i+1 contains x(i) and p(i), each an integer in the range 0..1,000,000.

输出格式:

  • Line 1: The maximum number of points Bessie can receive.

输入输出样例

输入样例#1:

6
5 6
1 1
10 5
7 6
4 8
8 10
输出样例#1:

25

说明

There are 6 targets. The first is at position x=5 and is worth 6 points, and so on.

Bessie hops from position x=4 (8 points) to position x=5 (6 points) to position x=7 (6 points) to position x=10 (5 points).

82分做法:

dp[i][j] 表示 i是由j转移过来的最大得分

枚举k转移

#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1001
using namespace std;
int n,ans,dp1[N][N],dp2[N][N];
struct node
{
int x,v;
}e[N];
bool cmp(node p,node q)
{
return p.x<q.x;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].v);
sort(e+,e+n+,cmp);
for(int i=;i<=n;i++)
for(int j=;j<i;j++)
{
for(int k=;k<j;k++)
{
if(e[i].x-e[j].x>=e[j].x-e[k].x) dp1[i][j]=max(dp1[i][j],dp1[j][k]);
if(e[i].x-e[j].x<=e[j].x-e[k].x) dp2[i][j]=max(dp2[i][j],dp2[j][k]);
}
dp1[i][j]=max(dp1[i][j],dp1[j][]);
dp1[i][j]+=e[i].v;
dp2[i][j]=max(dp2[i][j],dp2[j][]);
dp2[i][j]+=e[i].v;
ans=max(ans,max(dp1[i][j],dp2[i][j]));
}
printf("%d",ans);
}

55分做法:

记忆化搜索

#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1001
using namespace std;
int n,ans,dp1[N][N],dp2[N][N];
struct node
{
int x,v;
bool operator < (node p)const
{
return x<p.x;
}
}e[N];
int dfs1(int s,int t,int dis)
{
if(dp1[s][t]) return dp1[s][t];
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x>=dis) dp1[s][t]=max(dp1[s][t],dfs1(t,i,e[i].x-e[t].x)+e[i].v);
return dp1[s][t];
}
int dfs2(int s,int t,int dis)
{
if(dp2[s][t]) return dp2[s][t];
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x<=dis) dp2[s][t]=max(dp2[s][t],dfs2(t,i,e[i].x-e[t].x)+e[i].v);
return dp2[s][t];
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].v);
sort(e+,e+n+);
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
{ dp1[i][j]=dfs1(i,j,e[j].x-e[i].x)+e[i].v+e[j].v;
dp2[i][j]=dfs2(i,j,e[j].x-e[i].x)+e[i].v+e[j].v;
ans=max(ans,max(dp1[i][j],dp2[i][j]));
}
printf("%d\n",ans);
}

36分做法:

普通搜索

#include<cstdio>
#include<algorithm>
#define N 1001
using namespace std;
int n,ans;
struct node
{
int x,v;
bool operator < (node p)const
{
return x<p.x;
}
}e[N];
int dfs1(int s,int t,int dis,int sum)
{
ans=max(ans,sum);
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x>=dis) dfs1(t,i,e[i].x-e[t].x,sum+e[i].v);
}
int dfs2(int s,int t,int dis,int sum)
{
ans=max(ans,sum);
for(int i=t+;i<=n;i++)
if(e[i].x-e[t].x<=dis) dfs2(t,i,e[i].x-e[t].x,sum+e[i].v);
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].x,&e[i].v);
sort(e+,e+n+);
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
{
dfs1(i,j,e[j].x-e[i].x,e[i].v+e[j].v);
dfs2(i,j,e[j].x-e[i].x,e[i].v+e[j].v);
}
printf("%d\n",ans);
}

[USACO13NOV] Pogo-Cow的更多相关文章

  1. [luogu] P3089 [USACO13NOV]POGO的牛Pogo-Cow

    P3089 [USACO13NOV]POGO的牛Pogo-Cow 题目描述 In an ill-conceived attempt to enhance the mobility of his pri ...

  2. P3089 [USACO13NOV]POGO的牛Pogo-Cow

    P3089 [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路上进行练 ...

  3. DP【洛谷P3089】 [USACO13NOV]POGO的牛Pogo-Cow

    [洛谷P3089] [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路 ...

  4. 洛谷 3089 [USACO13NOV]POGO的牛Pogo-Cow

    单调队列优化dp; 对于每个点开个单调队列,按转移到它的点到它的距离从大到小,得分也从大到小排列. 每次枚举当前点前面的所有点,对于每个点的队列中二分一个距离小于等于它到当前点的答案值,放到当前点的队 ...

  5. dp专题练习

    顺便开另外一篇放一些学过的各种dp dp总结:https://www.cnblogs.com/henry-1202/p/9194066.html 开坑先放15道题,后面慢慢补 目标50道题啦~~,目前 ...

  6. 洛谷 P3088 [USACO13NOV]挤奶牛Crowded Cows 题解

    P3088 [USACO13NOV]挤奶牛Crowded Cows 题目描述 Farmer John's N cows (1 <= N <= 50,000) are grazing alo ...

  7. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  8. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  9. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

随机推荐

  1. 六: Image Viewer 离线镜像查看器

    参考:http://hadoop.apache.org/docs/r2.6.3/hadoop-project-dist/hadoop-hdfs/HdfsImageViewer.html   离线镜像查 ...

  2. RabbitMQ基本模式

    最近用到了一些RabbitMQ的东西,看了官方的Get Started,以此为模板总结一下. (1)生产者(发送方)发送消息到ExChange(含参:routingkey),ExChange通过bin ...

  3. Mac OS安装Scrapy失败

    报错: DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be re ...

  4. Swift-map()跟flatMap()区别

    map()方法介绍 map() 是  Array 提供的方法,通过接收一个函数作为传入参数,对数组中每个元素进行函数变换得到新的结果值.这样只需要提供  X->Y 的映射关系,就能将数组  [X ...

  5. ES6之 =>箭头函数

    原文,请点此链接http://www.cnblogs.com/allenxieyusheng/p/5784728.html 1. 第一个函数 ()=>1 解析:其实这是一个匿名函数直接执行 (f ...

  6. ci tp重定向

    server { listen 80; #listen [::]:80; server_name tpblog.yeves.com; index index.html index.htm index. ...

  7. Spring IOC原理简析

    所谓IoC, 就是一个用XML来定义生成对象的模式. 1.现有三个类,Human是接口,Chinese是一个实现类,American是另一个实现类. 2.获取以上对象采用工厂模式的用法如下: 创建一个 ...

  8. C#里面Console.Write()和Console.WriteLine()有什么区别?

    Console.Write()和Console.WriteLine()都是System.Console提供的方法,两着主要用来将输出流由指定的输出装置(默认为屏幕)显示出来.两着间的差异在Consol ...

  9. 每个zone的low memory是怎么计算出来的

    内核都是试图让活动页和不活动页的数量均衡 在分配内存时每次都会唤醒wakeup_swapd,这个函数会在 现在是不是已经没有全局的LRU表了?已经都变成per cgroup级别的LRU表了吗? ina ...

  10. TCP标志位简析

    TCP标志位简析   TCP标志位  URG:此标志表示TCP包的紧急指针域(后面马上就要说到)有效,用来保证TCP连接不被中断,并且督促中间层设备要尽快处理这些数据: ACK:此标志表示应答域有效, ...