[USACO13NOV] Pogo-Cow
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.
输入输出样例
6
5 6
1 1
10 5
7 6
4 8
8 10
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的更多相关文章
- [luogu] P3089 [USACO13NOV]POGO的牛Pogo-Cow
P3089 [USACO13NOV]POGO的牛Pogo-Cow 题目描述 In an ill-conceived attempt to enhance the mobility of his pri ...
- P3089 [USACO13NOV]POGO的牛Pogo-Cow
P3089 [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路上进行练 ...
- DP【洛谷P3089】 [USACO13NOV]POGO的牛Pogo-Cow
[洛谷P3089] [USACO13NOV]POGO的牛Pogo-Cow FJ给奶牛贝西的脚安装上了弹簧,使它可以在农场里快速地跳跃,但是它还没有学会如何降低速度. FJ觉得让贝西在一条直线的一维线路 ...
- 洛谷 3089 [USACO13NOV]POGO的牛Pogo-Cow
单调队列优化dp; 对于每个点开个单调队列,按转移到它的点到它的距离从大到小,得分也从大到小排列. 每次枚举当前点前面的所有点,对于每个点的队列中二分一个距离小于等于它到当前点的答案值,放到当前点的队 ...
- dp专题练习
顺便开另外一篇放一些学过的各种dp dp总结:https://www.cnblogs.com/henry-1202/p/9194066.html 开坑先放15道题,后面慢慢补 目标50道题啦~~,目前 ...
- 洛谷 P3088 [USACO13NOV]挤奶牛Crowded Cows 题解
P3088 [USACO13NOV]挤奶牛Crowded Cows 题目描述 Farmer John's N cows (1 <= N <= 50,000) are grazing alo ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心
SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
随机推荐
- Daily Scrum 10
今天我们小组开会内容分为以下部分: part 1: 经过反复思考,对于上次组会确定的在系统中加入娱乐版块进行了更进一步的商讨; part 2:继续探讨算法实现: part 3:进行明日的任务分配; ◆ ...
- C#控件DropDownList下拉列表默认打开
c#中的控件DropDownList要实现默打开确实不容易,之前也是想过页面上的点击之后就打开了,那直接模拟点击不就行了,试过后大失所望,根本没有效果. 于是网上找到了一个例子能实现IE浏览器下的打开 ...
- 【Linux】- ps -ef |grep 命令
ps:将某个进程显示出来 grep:查找 |:管道命令 表示ps命令与grep同时执行 PS是LINUX下最常用的也是非常强大的进程查看命令 grep命令是查找,是一种强大的文本搜索工具,它能使用正则 ...
- django使用ajax提交表单数据报403错解决方法
只需要在.ajaxSetup方法中设置csrfmiddlewaretoken即可 $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }} ...
- C#中的unsafe
为了保持类型安全性,默认情况下,C# 不支持指针算法. 但是,通过使用 unsafe 关键字,可以定义可在其中使用指针的不安全上下文. 有关指针的详细信息,请参阅主题指针类型. 备注 在公共语言运行时 ...
- Delphi 制作自定义数据感知控件并装入包(dpk文件)中(与DBText类似的数据感知控件)
一.基础知识简介: 1.包的命名介绍: 包的命名没有规则,但是建议遵守包的命名约定:包的命名与包的版本相关,包的名称前面几个字符通常表示作者或公司名,也可以是控件的一个描述词,后面紧跟的Std表示运行 ...
- Qt快速入门学习笔记(画图篇)
1.Qt中提供了强大的2D绘图系统,可以使用相同的API在屏幕和绘图设备上进行绘制,它主要基于QPainter.QPaintDevice和QPaintEngine这三个类.其中QPainter用来执行 ...
- BZOJ 2241 打地鼠(特技暴力)
果然暴力出奇迹.. O(n^2m^2)=1e8 536ms能过. 枚举锤子的长和宽,再验证是否可以满足条件并更新答案. 我们先从左上角为(1,1)的先锤,显然锤的次数是a[1][1]. 锤(i,j)的 ...
- [NOI2017]蔬菜 贪心
题面: [NOI2017]蔬菜 题解: 首先每天蔬菜会变质这点并不好处理,我们考虑让时间倒流,从后向前处理,这样的话就相当于每天都会得到一定量的蔬菜. 这样做有什么好处呢? 我们可以发现一个性质:如果 ...
- [bzoj4391] [Usaco2015 dec]High Card Low Card 贪心 线段树
---题面--- 题解: 观察到以决策点为分界线,以点数大的赢为比较方式的游戏都是它的前缀,反之以点数小的赢为比较方式的都是它的后缀,也就是答案是由两段答案拼凑起来的. 如果不考虑判断胜负的条件的变化 ...