Description

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), mt (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 abc, 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***********************************************************************************************************************************************************dfs()***********************************************************************************************************************************************************

 1 #include<iostream>
 2 #include<string>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<cstdio>
 6 #include<queue>
 7 bool vis[1001][1001];
 8 int jw[1001];
 9 int cost[1001][1001];
10 int maxn,s,e,n,m,t;
11 void dfs(int st,int jt,int cos)
12 {
13     if(st==e&&jt>maxn)
14         maxn=jt;
15     for(int it=0;it<n;it++)
16     {
17         if(!vis[st][it]&&st!=it&&cost[st][it]&&cos+cost[st][it]<=t)
18         {
19             int val=jw[it];
20             jw[it]=0;
21             vis[st][it]=true;
22             dfs(it,jt+val,cos+cost[st][it]);
23             jw[it]=val;
24             vis[st][it]=false;
25         }
26     }
27     return;
28 }
29 int main()
30 {
31     int i,j,k,a,b,w;
32     while(scanf("%d %d %d",&n,&m,&t)!=EOF)
33     {
34         scanf("%d %d",&s,&e);
35         memset(vis,false,sizeof(vis));
36         memset(cost,0,sizeof(cost));
37         for(i=0;i<n;i++)
38         {
39             scanf("%d",&jw[i]);
40         }
41         for(i=0;i<m;i++)
42         {
43             scanf("%d %d %d",&a,&b,&w);
44             cost[a][b]=cost[b][a]=w;
45         }
46         maxn=0;
47         int val=jw[s];
48         jw[s]=0;
49         dfs(s,val,0);
50         printf("%d\n",maxn);
51     }
52     return 0;
53 }

View Code

转载于:https://www.cnblogs.com/sdau--codeants/p/3440458.html

Escape Time II 简单的深搜dfs()相关推荐

  1. 深入递归、深搜dfs、回溯、剪纸学习。

    深入递归,深搜dfs,回溯,剪枝 参考于博客 一.双管齐下解递归 "逐步生成结果"类问题之数值型 自下而上的递归(递推,数学归纳,动态规划) 解决简单情况下的问题. 推广到稍复杂情 ...

  2. [二叉树|深搜|dfs] leetcode 404 左叶子之和

    [二叉树|深搜|dfs] leetcode 404 左叶子之和 1.题目 题目链接 计算给定二叉树的所有左叶子之和. 示例: 3/ \9 20/ \15 7在这个二叉树中,有两个左叶子,分别是 9 和 ...

  3. 题解HDU6148 Valley Numer(数位DP+深搜DFS)

    题解HDU6148 Valley Numer[数位DP+深搜DFS] 题目 解析 参考源码 题目 Description: 众所周知,度度熊非常喜欢数字. 它最近发明了一种新的数字:Valley Nu ...

  4. 2412 - 和为K ---深搜dfs剪枝

    **2412 - 和为K ---深搜dfs优化 **来源:东方博宜oj oj.czos.cn #include<bits/stdc++.h> using namespace std; co ...

  5. acwing-167. 木棒(深搜dfs+减枝)

    乔治拿来一组等长的木棒,将它们随机地砍断,使得每一节木棍的长度都不超过 50 个长度单位. 然后他又想把这些木棍恢复到为裁截前的状态,但忘记了初始时有多少木棒以及木棒的初始长度. 请你设计一个程序,帮 ...

  6. 深搜DFS\广搜BFS 图初步入门

    首先,不管是BFS还是DFS,由于时间和空间的局限性,它们只能解决数据量比较小的问题. 深搜,顾名思义,它从某个状态开始,不断的转移状态,直到无法转移,然后退回到上一步的状态,继续转移到其他状态,不断 ...

  7. 算法学习笔记(六) 二叉树和图遍历—深搜 DFS 与广搜 BFS

    图的深搜与广搜 复习下二叉树.图的深搜与广搜. 从图的遍历说起.图的遍历方法有两种:深度优先遍历(Depth First Search), 广度优先遍历(Breadth First Search),其 ...

  8. 深搜(DFS),Image Perimeters

    题目链接:http://poj.org/problem?id=1111 解题报告: 1.这里深搜有一点要注意,对角线上的点,如果为'.',则total不应该增加,因为这不是他的边长. #include ...

  9. 习题9-2(免费糖果)【深搜dfs】+【记忆化搜索】

    习题9-2 [UVa 10118]Free Candies(免费糖果) 题目大意: 桌上有4堆糖果,每堆有N(N<=40)颗.佳佳有个最多可以装5颗糖果的小篮子.他每次选择一堆糖果,把最顶上的一 ...

最新文章

  1. FMDatabase常见的几个操作
  2. .NET 数据库缓存依赖策略实现
  3. linux中权限对文件和目录的意义
  4. discuz二次元文章博客模板
  5. TensorFlow神经网络(八)卷积神经网络之Lenet-5
  6. yaml 变量引用_Yaml语法使用
  7. 新型城镇化提质扩容 打造民村智慧城市
  8. 安装wincap时报错解决方式: an error occured when installing winpcap 0x00000430
  9. 文档中心 统计分析 统计分析Android文档 集成文档
  10. GMS认证环境搭建-终极篇
  11. 《自控力》直面自身欲望,但不要付诸行动
  12. ABP框架源码中的Linq扩展方法
  13. 从键盘读入学生成绩,找出最高分, 并输出学生成绩等级
  14. 【大数据存储技术】思考题及参考答案
  15. Python pandas.DataFrame.expanding函数方法的使用
  16. Shiro框架基础及搭建
  17. 微信小程序 API的 promise化
  18. 医学统计学中差异性检验的检验方法选择
  19. Linux 系统安全加固篇之安全加固脚本
  20. ultraedit删除重复项_UltraEdit技巧点点滴滴

热门文章

  1. oracle 数据泵导出简单使用版
  2. C# 7.2和8.0路线图
  3. 全检体系结构风格浅谈
  4. android 中处理崩溃异常并重启程序
  5. jQuery对select操作
  6. 解决:No configuration found. Configuring ehcache from ehcache-failsafe.xml 问题
  7. [Hadoop in China 2011] Facebook Message在HBase基础上的应用
  8. es6+最佳入门实践(10)
  9. Leetcode-探索 | 加一
  10. Centos 6.8 搭建owncloud 私有云盘