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 ≤ ct)
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的更多相关文章

  1. 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 ...

  2. zoj 3356 Football Gambling II【枚举+精度问题】

    题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...

  3. ZOJ 3332 Strange Country II

    Strange Country II Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge You want to v ...

  4. ZOJ 3042 City Selection II 【序】【离散化】【数学】

    题意: 输入数据n,m.n代表工厂的数量,m代表城市的数量. 接下来n+m行为工厂和城市的坐标. 规定如图所示方向刮风,工厂的air会污染风向地区的air. 注意,工厂和城市的坐标表示的是从x到x+1 ...

  5. zoj 3627 Treasure Hunt II (贪心)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:zoj-3627 题意 直线上有n个城市, 第i个城市和i+1个城市是相邻的.  每个城市都有vi的金币.   ...

  6. 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 ...

  7. ZOJ 3332 Strange Country II (竞赛图构造哈密顿通路)

    链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3332 本文链接:http://www.cnblogs.com/Ash-l ...

  8. ZOJ 3627 Treasure Hunt II (贪心,模拟)

    题意:有n个城市并排着,每个城市有些珠宝,有两个人站在第s个城市准备收集珠宝,两人可以各自行动,但两人之间的距离不能超过dis,而且每经过一个城市就需要消耗1天,他们仅有t天时间收集珠宝,问最多能收集 ...

  9. ZOJ 3466 The Hive II (插头DP,变形)

    题意:有一个n*8的蜂房(6边形的格子),其中部分是障碍格子,其他是有蜂蜜的格子,每次必须走1个圈取走其中的蜂蜜,在每个格子只走1次,且所有蜂蜜必须取走,有多少种取法? 思路: 以前涉及的只是n*m的 ...

随机推荐

  1. Android从服务端获取json解析显示在客户端上面

    Android从服务端获取json解析显示在客户端上面 百度经验:jingyan.baidu.com 首先说一下Json数据的最基本的特点,Json数据是一系列的键值对的集合,和XML数据来比,Jso ...

  2. ubuntu vim 插件安装

    参考:http://blog.sina.com.cn/s/blog_00f0230d0100y7ih.html 不过由于时间久远,有些已经失效,以上是我的修改过程 参考:https://github. ...

  3. Makefile隐含规则和用到的默认变量

    如果要使用隐含规则生成你需要的目标,你所需要做的就是不要写出这个目标的规则.那么,make会试图去自动推导产生这个目标的规则和命令,如果make可以自动推导生成这个目标的规则和命令,那么这个行为就是隐 ...

  4. 【原创】Linux opensource-src-4.3.2.tar.gz的安装。

    下载好opensource-src-4.3.2.tar.gz 安装G++等必备库: sudo apt-get install make gcc g++ sudo apt-get install bui ...

  5. write() ,read();

    int main1(int argc ,char *argv[]){ if(argc < 2 ) return 0; int fd = open(argv[1] , O_RDONLY); if( ...

  6. windows 环境下安装plpython语言环境到postgresql数据库

    1.1       安装plpython 在windows环境 1.1.1      下载http://legacy.python.org/ftp//python/3.2.5/python-3.2.5 ...

  7. Python的简介以及安装和第一个程序以及用法

    Python的简介: 1.Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.自从20世纪90年代初Python语言诞生至今,它逐渐被广泛应用于处理系统管理任务和Web编程.Pytho ...

  8. List<>.Contains<>的用法

    List<Plan> Plans = new List<Plan>();//存放服务器中的当前用户所接受的项目计划列表. //Plan 类包含PlanID等属性. if (Pl ...

  9. c++11的for新用法 (重新练习一下for_each)

    看到手册的代码里面有个for的很奇怪的用法,用了一把    http://www.cplusplus.com/reference/unordered_set/unordered_set/insert/ ...

  10. SEVERE: Error listenerStart

    转载:http://blog.sina.com.cn/s/blog_43eb83b90102e2k6.html# 今天启动Tomcat启动不了,报以下错:org.apache.catalina.cor ...