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. asp.net:录入数据库的中文变问号

    表格是可以接受中文的: 类型也是nvarchar的: 还是出现写中文变问号?? 这时候请加入转义大写N: 如: 原查询语句:insert into table1(name)  values('蜘蛛侠' ...

  2. poj2104:K-th Number

    思路:可持久化线段树,利用权值线段树,把建树过程看成插入,插入第i个元素就在第i-1棵树的基础上新建结点然后得到第i棵树,那么询问区间[l,r]就是第r棵树上的信息对应减去第l-1棵树上的信息,然后再 ...

  3. 无刷新删除 Ajax,JQuery

    1.数据库用上面的,增加一个 DeleteById 的SQL方法 delete from T_Posts where Id = @Original_Id 2.设置处理页面 delete.ashx pu ...

  4. Linux下通过软链接转移mysql目录,解决分区空间不足(转)

    http://darwinclub.info/wp/?p=454(转) 当存放数据库分区的空间不足时,可以采取对数据库目录进行迁移的方法,具体步骤如下:1.先关闭数据库mysqladmin -p sh ...

  5. Unix环境高级编程学习笔记——fcntl

    写这篇文正主要是为了介绍下fcntl,并将我自己在学习过程中的一些理解写下来,不一定那么官方,也有错误,希望指正,共同进步- fcntl: 一个修改一打开文件的性质的函数.基本的格式是 int fcn ...

  6. IBUS-WARNING **: Process Key Event failed: Timeout was reached

    在gvim中ibus敲字时,偶尔会在n秒之后才显示到屏幕,反应死慢.控制台会看到下面的错误信息. (gvim:): IBUS-WARNING **: Process Key Event failed: ...

  7. sed工具使用

    sed命令使用形式 1.sed命令从管道中读取数据处理 command | sed ' edit command' 通过管道把一个命令的标准输出读入到sed的标准输入,sed就起到了过滤作用 2.se ...

  8. NetSerialComm的基本使用方法

    近期搞一个com口传输的小项目,原来认为是一个挺简单的一个小功能,结果生产商发来com以后直接傻眼了,还要对相关的硬件流进行处理 如下 // 硬件流控制设置 dcb.fOutxCtsFlow = FA ...

  9. jquery解析XML(1)

    jquery解析XML文件 html代码 <!DOCTYPE html><html><head><title>解析XML</title>&l ...

  10. express的基本配置项

    express自动生成的app.js中有一段代码用app.set和app.use对express进行配置,但这些配置都是什么意思,以及都能做哪些配置并没有展开.这一节就专门来讲express的配置.上 ...