zoj 3620 Escape Time II
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4744
Escape Time II
Time Limit: 2 Seconds Memory Limit: 65536 KB
There is a fire in LTR ’ s home again. The fire can destroy all the things in t seconds, so LTR has to escape in t seconds. But there are some jewels in LTR ’ s rooms, LTR love jewels very much so he wants to take his jewels as many as possible before he goes to the exit. Assume that the ith room has ji jewels. At the beginning LTR is in room s, and the exit is in room e.
Your job is to find a way that LTR can go to the exit in time and take his jewels as many as possible.
Input
There are multiple test cases.
For each test case:
The 1st line
contains 3 integers n (2 ≤ n ≤ 10), m,
t (1 ≤ t ≤ 1000000) indicating the number of rooms, the
number of edges between rooms and the escape time.
The 2nd line contains 2
integers s and e, indicating the starting room and the
exit.
The 3rd line contains n integers, the ith
interger ji (1 ≤ ji ≤ 1000000)
indicating the number of jewels in the ith room.
The next
m lines, every line contains 3 integers a, b,
c, indicating that there is a way between room a and room
b and it will take c (1 ≤ c ≤ t)
seconds.
Output
For each test cases, you should print one line contains one integer the
maximum number of jewels that LTR can take. If LTR can not reach the exit in
time then output 0 instead.
Sample Input
3 3 5
0 2
10 10 10
0 1 1
0 2 2
1 2 3
5 7 9
0 3
10 20 20 30 20
0 1 2
1 3 5
0 3 3
2 3 2
1 2 5
1 4 4
3 4 2
Sample Output
30
80
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxx = ;
int Edge[maxx][maxx];
int val[maxx];
bool vis[maxx];
int big = ,e,n,t;
void dfs(int s, int num,int ju)
{
if(num>t) return; if(s == e)
if(ju > big && num<=t)
big = ju; vis[s] = true;
for(int i=;i<n;i++)
{
if(i!=s && Edge[s][i]<1e8 && !vis[i])
{
dfs(i,num + Edge[s][i],ju + val[i]);
}
}
vis[s] = false; }
void Floyd()
{
for(int i=; i<n;i++)
for(int j=; j<n; j++)
for(int k=; k<n; k++)
if(Edge[j][i] + Edge[i][k] < Edge[j][k])
Edge[j][k] = Edge[j][i] + Edge[i][k];
}
int main()
{
int m;
int s;
while(~scanf("%d %d %d",&n,&m,&t))
{
memset(Edge,0x6,sizeof(Edge));
memset(val,,sizeof(val));
memset(vis,,sizeof(vis));
scanf("%d %d",&s,&e);
for(int i=;i<n;i++)
scanf("%d",&val[i]);
for(int i=;i<=m;i++)
{
int u,v,w;
scanf("%d %d %d",&u,&v,&w);
Edge[u][v] = Edge[v][u] = w;
}
Floyd();
big = ;
vis[s] = true;
dfs(s,,val[s]);
printf("%d\n",big);
}
return ;
}
zoj 3620 Escape Time II的更多相关文章
- zoj 3620 Escape Time II dfs
题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...
- zoj 3356 Football Gambling II【枚举+精度问题】
题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...
- ZOJ 3332 Strange Country II
Strange Country II Time Limit: 1 Second Memory Limit: 32768 KB Special Judge You want to v ...
- ZOJ 3042 City Selection II 【序】【离散化】【数学】
题意: 输入数据n,m.n代表工厂的数量,m代表城市的数量. 接下来n+m行为工厂和城市的坐标. 规定如图所示方向刮风,工厂的air会污染风向地区的air. 注意,工厂和城市的坐标表示的是从x到x+1 ...
- zoj 3627 Treasure Hunt II (贪心)
本文出自 http://blog.csdn.net/shuangde800 题目链接:zoj-3627 题意 直线上有n个城市, 第i个城市和i+1个城市是相邻的. 每个城市都有vi的金币. ...
- ZOj 3466 The Hive II
There is a hive in the village. Like this. There are 8 columns(from A to H) in this hive. Different ...
- ZOJ 3332 Strange Country II (竞赛图构造哈密顿通路)
链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3332 本文链接:http://www.cnblogs.com/Ash-l ...
- ZOJ 3627 Treasure Hunt II (贪心,模拟)
题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集 ...
- ZOJ 3466 The Hive II (插头DP,变形)
题意:有一个n*8的蜂房(6边形的格子),其中部分是障碍格子,其他是有蜂蜜的格子,每次必须走1个圈取走其中的蜂蜜,在每个格子只走1次,且所有蜂蜜必须取走,有多少种取法? 思路: 以前涉及的只是n*m的 ...
随机推荐
- iOS9 UITableViewCell separatorInset设置为0分割线还是没有顶到头的问题
只需要在自定义的Cell中添加以下代码即可 override func awakeFromNib() { super.awakeFromNib() layoutMargins = UIEdgeInse ...
- Prism for WPF 第一讲 Event机制
在本篇文章中主要讲解在Prism中模块与模块之间事件关联的机制.在这里牵涉到三个名词:事件定义,事件发布,事件订阅. 第一:事件定义 在公共类库中定义事件. ①没有参数事件 public class ...
- 选择第n小的元素之python实现源码
def partition(A, p, r): j = p+1 for i in range(p+1, r+1): if(A[i] < A[p]): tmp = A[i] A[i] = A[j] ...
- python 自动化之路 day 06
ATM作业讲解: 数据访问层 业务逻辑层 time & datetime模块 import time # print(time.clock()) #返回处理器时间,3.3开始已废弃 , 改成了 ...
- Centos学习手册——装逼宝典之强制重置密码
---恢复内容开始--- Centos学习手册by RuffianFish; 痞子鱼 近日闲的无聊,而最近又在搞Centos决定写个Centos详细的学习手册,以便自己在长时间没摸Centos的情况下 ...
- Java RMI(远程方法调用)开发
参考 https://docs.oracle.com/javase/7/docs/platform/rmi/spec/rmi-arch2.html http://www.cnblogs.com/wxi ...
- 《工作型PPT设计之道》培训心得
参加包翔老师的“工作型PPT设计之道>培训,颇多心得,后来为部门新员工和同组同事做了转化培训,将心得整理成一份PPT讲义,效果颇佳.现将主要心得整理于此.因时间仓促,24条心得有拼凑之嫌,有待今 ...
- 【转】iOS设计模式之观察者模式
参考:http://blog.csdn.net/xdrt81y/article/details/24039163 或者 http://blog.jobbole.com/55505/
- string内存管理
本人从事.net开发快两年了,一直认为鄙人的C++基础还是很扎实的,并且对Windows操作系统也有一定认识(Linux系就真比较少用),刚毕业的时候,也曾经经常研究游戏破解之类的小外挂,那时候真是折 ...
- easyui之combotree
这几天时间比较空闲的我把easyui中比较难的控件回顾一遍 这次的总结是easyui中的combotree easyui的中文文档上说:combotree结合选择控制和下拉树,类似于combobox只 ...