bzoj1663: [Usaco2006 Open]赶集
Description
Every year, Farmer John loves to attend the county fair. The fair has N booths (1 <= N <= 400), and each booth i is planning to give away a fabulous prize at a particular time P(i) (0 <= P(i) <= 1,000,000,000) during the day. Farmer John has heard about this and would like to collect as many fabulous prizes as possible to share with the cows. He would like to show up at a maximum possible number of booths at the exact times the prizes are going to be awarded. Farmer John investigated and has determined the time T(i,j) (always in range 1..1,000,000) that it takes him to walk from booth i to booth j. The county fair's unusual layout means that perhaps FJ could travel from booth i to booth j by a faster route if he were to visit intermediate booths along the way. Being a poor map reader, Farmer John never considers taking such routes -- he will only walk from booth i to booth j in the event that he can actually collect a fabulous prize at booth j, and he never visits intermediate booths along the way. Furthermore, T(i,j) might not have the same value as T(j,i) owing to FJ's slow walking up hills. Farmer John starts at booth #1 at time 0. Help him collect as many fabulous prizes as possible.
Input
* Line 1: A single integer, N.
* Lines 2..1+N: Line i+1 contains a single integer, P(i). * Lines 2+N..1+N+N^2: These N^2 lines each contain a single integer T(i,j) for each pair (i,j) of booths. The first N of these lines respectively contain T(1,1), T(1,2), ..., T(1,N). The next N lines contain T(2,1), T(2,2), ..., T(2,N), and so on. Each T(i,j) value is in the range 1...1,000,000 except for the diagonals T(1,1), T(2,2), ..., T(N,N), which have the value zero.
Output
* Line 1: A single integer, containing the maximum number of prizes Farmer John can acquire.
输出一个整数,即约翰最多能拿到的礼物的个数
Sample Input
13 //第一个东西,在第一个地点第13分钟掉下来
9 //第二个东西,在第二个地点第9分钟掉下来
19 //第三个东西,在第三个地点第19分钟掉下来
3 //这是第四个东西.
0 //这下面有4*4行,代表每个点到其它点的要花的时间,自己到自己的时间为0。
10
20
3
4
0
11
2
1
15
0
12
5
5
13
0
Sample Output
Farmer John first walks to booth #4 and arrives at time 3, just in
time to receive the fabulous prize there. He them walks to booth
#2 (always walking directly, never using intermediate booths!) and
arrives at time 8, so after waiting 1 unit of time he receives the
fabulous prize there. Finally, he walks back to booth #1, arrives
at time 13, and collects his third fabulous prize.
HINT
想写最短路然鹅不会.....
但是可以dp
设$f[i]$表示走到点$i$时最多可以拿几个礼物
当$time[j]+d[j][i]<=time[i]$时,就可以转移状态$f[i]=max(f[i],f[j]+1)$
每个点事先按时间排序就好了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int max(int a,int b){return a>b?a:b;}
#define N 405
struct data{int t,id;}a[N];
bool cmp(const data &A,const data &B){return A.t<B.t;}
int n,d[N][N],ans,f[N];
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%d",&a[i].t),a[i].id=i;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
scanf("%d",&d[i][j]);
sort(a+,a+n+,cmp);
for(int i=;i<=n;++i){
if(d[][a[i].id]<=a[i].t) f[i]=;
for(int j=;j<i;++j)
if(a[j].t+d[a[j].id][a[i].id]<=a[i].t)
f[i]=max(f[i],f[j]+);
ans=max(ans,f[i]);
}printf("%d",ans);
return ; }
bzoj1663: [Usaco2006 Open]赶集的更多相关文章
- 【动态规划】bzoj1663 [Usaco2006 Open]赶集
http://blog.csdn.net/u011265346/article/details/44906469 #include<cstdio> #include<algorith ...
- [BZOJ1663] [Usaco2006 Open]赶集(spfa最长路)
传送门 按照时间t排序 如果 t[i] + map[i][j] <= t[j],就在i和j之间连一条边 然后spfa找最长路 #include <queue> #include &l ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
- 【刷题记录】BZOJ-USACO
接下来要滚去bzoj刷usaco的题目辣=v=在博客记录一下刷题情况,以及存一存代码咯.加油! 1.[bzoj1597][Usaco2008 Mar]土地购买 #include<cstdio&g ...
- usaco silver
大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草 裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...
- bzoj usaco 金组水题题解(2)
续.....TAT这回不到50题编辑器就崩了.. 这里塞40道吧= = bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 比较经典的最小割?..然而 ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- USACO 刷题记录bzoj
bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草——背包 #include<cstdio> #include<cstring> #incl ...
随机推荐
- Java学习路径及练手项目合集
Java 在编程语言排行榜中一直位列前排,可知 Java 语言的受欢迎程度了. 实验楼上的[Java 学习路径]中将首先完成 Java基础.JDK.JDBC.正则表达式等基础实验,然后进阶到 J2SE ...
- PowerDesigner安装及破解
1.复制pdflm16.dll文件. 2.. 找到PowerDesigner16.5的安装目录,然后粘贴pdflm16.dll,替换安装目录里面的pdflm16.dll文件: 3.重新启动PowerD ...
- SQL _ Create Procedure
-- ================================================ -- Template generated from Template Explorer usi ...
- Please add or free up more resources then turn off safe mode manually.
解决方案:硬盘满了,释放硬盘空间.
- iOS 开发笔记-报错处理
1.xcode7报错:does not contain bitcode 解决方法:Build Settings 搜索 bitcode 将Enable Bitcode更改为NO即可 2.Code Si ...
- Linux SSH 免秘钥登录
SSH 免秘钥登录 ssh:是一种安全加密协议 ssh username@hostname ssh gongziyuan.com:以当前用户登录该机器(如果不是当前用户,需要这么干:ssh ...
- MySQL创建外键约束的报错Error : Can't create table '#sql-534_185' (errno: 150)
总得来说是因为两个表的字段类型不一致,例如: 两个字段的类型或大小不严格匹配,一个为tinyint,另一个为char:或一个为int(10)另一个为int(9)也是不行的,即使都为int(10),但一 ...
- 17.Setters/getters
知道类的成员变量何时因某种原因发生变化通常很有用.也可能需要以某种方式封装其访问. 为此,GDScript使用 setget 关键字提供了一个 setter/getter 语法.在变量定义后可直接使用 ...
- html5-浮动
#div1{ background: rgba(255,0,0,0.5); width: 250px; height: 250px; float: right;}#div2{ ...
- Sitecore CMS中的项目如何配置帮助文本
如何在Sitecore CMS中的项目上配置帮助文本. 所有Sitecore项目都有长短描述字段,以及“帮助链接”字段.这些字段有助于向内容编辑者提供其他信息.这对于很少编辑的项目和字段尤其重要,因为 ...