SOJ2505: The County Fair题解动态规划
来源:互联网 发布:java火车票售票系统 编辑:程序博客网 时间:2024/05/05 22:37
2505: The County Fair
Submit your solution Discuss this problem Best solutions
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
The input file contains multiple test cases, for each test case:
* 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.
Process till EOF.
Output
For each test case, output:
* Line 1: A single integer, containing the maximum number of prizes Farmer John can acquire.
Sample Input
41391930102034011211501255130
Sample Output
3
Source
U S OPEN, 2006 USACO Contest
状态:
d[i]表示到第i个最大值
状态转移方程
d[i]=max(d[j]+1)
if(d[j]&&p[i].n>=a[p[j].d][p[i].d]+p[j].n)
边界:
if(a[1][p[i].d]<=p[i].n)
d[i]=1;
代码:
- SOJ2505: The County Fair题解动态规划
- SOJ 2505: The County Fair
- soj 2505: The County Fair(离散化 + 记忆化搜索)
- POJ3666Making the Grade题解动态规划DP
- POJ3186Treats for the Cows题解动态规划DP
- I'm Attacking the Darkness!题解动态规划DP
- hdu 2224 The shortest path 题解(动态规划)
- POJ3666 Making the Grade题解-动态规划dp
- HUST1380NumberPyramids题解动态规划
- 动态规划初级题解
- 动态规划中级题解
- bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
- [BZOJ1664] [Usaco2006 Open]County Fair Events 参加节日庆祝
- 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝
- BZOJ 1664 [Usaco2006 Open] County Fair Events 参加节日庆祝
- [Usaco2006 Open]County Fair Events 参加节日庆祝
- Bookshelf题解动态规划DP
- POJ2353Ministry题解动态规划DP
- 关于form表单的submit提交时对象没有该属性和方法问题
- 读者与写者问题
- Java 面板切换问题
- ARM 面积评估
- VTK5.6.0在BCB6下的编译问题之一 remove的问题
- SOJ2505: The County Fair题解动态规划
- startActivityForResult 用法
- 栈的简单实现
- 数据结构——单链表
- 数据结构——单链表
- 电脑突然死机后黑屏
- 笔记
- 笔记
- ACE线程管理机制-线程的创建与管理