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. HDU 4308 Saving Princess claire_(简单BFS)

    求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...

  2. 使用HTML5制作loading图

    昨天发了一篇使用HTML5 canvas写的时钟的文章,今天发一篇关于使用HTML5制作loading图的文章. <!DOCTYPE html> <html> <head ...

  3. Nodejs中关于模块的总结

    关于Nodejs中的模块 概念 Nodejs在ECMAScript的基础上扩展并封装了许多高级特性,如文件访问.网络访问等,使得Nodejs成为一个很好的Web开发平台.基于Nodejs这个平台将We ...

  4. ueditor百度编辑器的赋值方法

    示例: http://ueditor.baidu.com/website/onlinedemo.html 引用代码: window.UMEDITOR_HOME_URL = $CONFIG['domai ...

  5. Android - TabHost 选项卡功能用法详解

    TabHost效果图 : 源码下载地址 : http://download.csdn.net/detail/han1202012/6845105        . 作者 :万境绝尘  转载请注明出处  ...

  6. lintcode-33-N皇后问题

    33-N皇后问题 n皇后问题是将n个皇后放置在n*n的棋盘上,皇后彼此之间不能相互攻击. 给定一个整数n,返回所有不同的n皇后问题的解决方案. 每个解决方案包含一个明确的n皇后放置布局,其中" ...

  7. 阻塞 , 非阻塞 , 同步 ,异步 , I/O模型

    •阻塞,非阻塞:进程/线程要访问的数据是否就绪,进程/线程是否需要等待: •同步,异步:访问数据的方式,同步需要主动读写数据,在读写数据的过程中还是会阻塞:异步只需要I/O操作完成的通知,并不主动读写 ...

  8. 苹果ATS特性服务器配置指南 HTTPS 安卓可以用 IOS 报错。

    解决方案:https://www.qcloud.com/document/product/400/6973 ATS检测:https://www.qcloud.com/product/ssl#userD ...

  9. 使用Gulp实现网页自动刷新:gulp-connect

    入门指南 1. 全局安装 gulp: npm install --global gulp 2. 作为项目的开发依赖(devDependencies)安装: npm install --save-dev ...

  10. FLT_MIN,FLT_MAX,FLT_EPSILON

    FLT_MIN,FLT_MAX,FLT_EPSILON  * min positive value */最小的正值#define FLT_MIN 1.175494351e-38F /* max val ...