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.

每一年,约翰都会带着他的奶牛们去赶集.集会中一共有N(1≤N≤400)个商店,第i个商店会在特定的时间Pi(0≤Pi≤109)对当时在店里的顾客送出一份精美的礼物.约翰当然得到了这个消息,于是他希望能拿到尽量多的礼物送给他的奶牛们.也就是说,他想尽可能多地在某商店发放礼物的时候,正好呆在店里.
    经过一定的调查,约翰弄清楚了从i号商店走到J号商店所需要的时间Ti,J(1≤Ti,J≤1000000).虽然乡间小路奇特的布局使得从i号商店走到j号商店的最短路不一定是直接连接这两个商店的那条,但约翰并不会选择那些会经过其他商店的路线,只是直接走到目标商店等待礼物的送出.此外,Ti,j并不一定等于Tj,i,由于约翰爬山的速度总是很慢.
    约翰在时间0时于1号商店开始他的旅途.请你帮他设计一条路线来获得尽可能多的礼物.

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.

  第1行输入一个正整数N.接下来N行每行一个整数Pi.
    接下来N^2行,输入乃,J.先输入T1,1 T1,2 T1,3…T1,N再输入T2,1 T2,2…T2,N依次类推.

Output

* Line 1: A single integer, containing the maximum number of prizes Farmer John can acquire.

输出一个整数,即约翰最多能拿到的礼物的个数

Sample Input

4 //有四个收藏品可以去收集,下面四行给出这四个东西下落的时间
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

3

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

    一共有4家商店.1号商店会在时间13送出一份礼物,2号商店送出礼物的时间为9,3号商店是时间19,4号商店是时间3.    约翰先在时间3走到4号商店,正好拿到送出的礼物.然后他再直接走到2号商店(不经过任何中转商店),在时间8到那儿,然后等待1单位时间,在时间9拿到商店送出的礼物后马上出发去1号商店,又正好能在时间13到达并拿到第3份礼物.

想写最短路然鹅不会.....

但是可以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]赶集的更多相关文章

  1. 【动态规划】bzoj1663 [Usaco2006 Open]赶集

    http://blog.csdn.net/u011265346/article/details/44906469 #include<cstdio> #include<algorith ...

  2. [BZOJ1663] [Usaco2006 Open]赶集(spfa最长路)

    传送门 按照时间t排序 如果 t[i] + map[i][j] <= t[j],就在i和j之间连一条边 然后spfa找最长路 #include <queue> #include &l ...

  3. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

  4. 【刷题记录】BZOJ-USACO

    接下来要滚去bzoj刷usaco的题目辣=v=在博客记录一下刷题情况,以及存一存代码咯.加油! 1.[bzoj1597][Usaco2008 Mar]土地购买 #include<cstdio&g ...

  5. usaco silver

    大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草   裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...

  6. bzoj usaco 金组水题题解(2)

    续.....TAT这回不到50题编辑器就崩了.. 这里塞40道吧= = bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 比较经典的最小割?..然而 ...

  7. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. USACO 刷题记录bzoj

    bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草——背包 #include<cstdio> #include<cstring> #incl ...

随机推荐

  1. IOC解耦-面向接口编程的优点

    原文:https://blog.csdn.net/jj_nan/article/details/70161086 参考:https://www.cnblogs.com/landeanfen/p/477 ...

  2. Python3.6下使用会话session保持登陆状态

    本次工具主要利用python easygui模块的inputbox让用户首次输入登陆信息,作为网站requests-post请求的data字段,观察XHR(异步加载)的数据包,构造post请求,利用r ...

  3. 带你零基础学习HTML5

    1个HTML5基础入门教程,4个HTML5小项目教程,带你零基础入门学习HTML5. [HTML5基础入门] 教程将会介绍HTML5中的新特性,包括结构标签.新型表单标签.文件操作.Canvas.本地 ...

  4. git checkout .还可以恢复吗

    说实话,希望很渺茫, 如果你在git  checkout . 之前操作了git stash ,还是可以恢复的,操作如下: 最后修改文件恢复了! 但是如果你在git checkout .之前没有git ...

  5. [LeetCode] 747. Largest Number At Least Twice of Others_Easy

    In a given integer array nums, there is always exactly one largest element. Find whether the largest ...

  6. node微信公众号开发---自动回复

    微信开发的特点:1.post请求 (一定要注意,这里和配置域名的时候不一样,配置域名是get请求)2.数据包是xml格式的3.你给微信返回的数据也是xml格式的 var parseString = r ...

  7. 关于RBAC的文章

    权限系统与RBAC模型概述 RBAC权限管理模型 摘自慕课网的RBAC

  8. iOS 新浪微博-2.0 搜索框/标题带箭头/下拉菜单

    不管是搜索框还是下拉菜单,我们都需要对背景的图片进行拉伸.定义一个Category分类对图片进行操作. UIImage+Effect.h #import <UIKit/UIKit.h> @ ...

  9. 了解tomcat

    tomcat:是一个轻量级的应用服务器,中小型公司使用,部署和发布项目,响应html bin:存放二进制文件,startup.bat:启动文件,shutdown.bat关闭文件 conf:server ...

  10. springmvc注解式开发

    搭建环境 后端控制器无需实现接口,添加相应的注解 springmvc配置文件中无需注册controller springmvc配置文件中添加组件扫描器.注解驱动 涉及常用的注解 @controller ...