题目链接:

题目

Escape Time II

Time Limit: 20 Sec

Memory Limit: 256 MB

问题描述

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.

输入

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.

输出

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.

样例

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

output

30

80

题意

给你一个无向图,问在规定时间内从起点走到终点能带走的最多珠宝。

题解

n才10,直接暴搜。

代码

zoj崩了,代码还没提交,先放着吧orz

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn = 22;
const int INF = 0x3f3f3f3f; int G[maxn][maxn];
int vis[maxn],val[maxn];
int n, m, k,st,ed;
int ans; void dfs(int u,int d,int cnt) {
if (d > k) return;
if (u == ed) ans = max(ans, cnt);
for (int i = 0; i < n; i++) {
if (i == u) continue;
int t = val[i]; val[i] = 0;
dfs(i, d + G[u][i],cnt+t);
val[i] = t;
}
} void init() {
memset(vis, 0, sizeof(vis));
memset(G, INF, sizeof(G));
} int main() {
while (scanf("%d%d%d", &n, &m, &k) == 3 && n) {
init();
scanf("%d%d", &st, &ed);
for (int i = 0; i < n; i++) scanf("%d", &val[i]);
while (m--) {
int u, v,w;
scanf("%d%d%d", &u, &v, &w);
G[u][v] = G[v][u] = min(G[u][v], w);
}
ans = 0;
vis[st] = 1;
int t = val[st]; val[st] = 0;
dfs(st,0,t);
printf("%d\n", ans);
}
return 0;
}

zoj 3620 Escape Time II dfs的更多相关文章

  1. zoj 3620 Escape Time II

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4744 Escape Time II Time Limit: 2 Seconds ...

  2. ZOJ 3631 Watashi's BG DFS

    J - Watashi's BG Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Subm ...

  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 3356 Football Gambling II【枚举+精度问题】

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

  5. ZOJ 4124 拓扑排序+思维dfs

    ZOJ - 4124Median 题目大意:有n个元素,给出m对a>b的关系,问哪个元素可能是第(n+1)/2个元素,可能的元素位置相应输出1,反之输出0 省赛都过去两周了,现在才补这题,这题感 ...

  6. ZOJ 1002 Fire Net(dfs)

    嗯... 题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364501 这道题是想出来则是一道很简单的dfs: 将一 ...

  7. ZOJ 3644 Kitty's Game dfs,记忆化搜索,map映射 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 从点1出发,假设现在在i,点数为sta,则下一步的点数必然不能是sta的 ...

  8. ZOJ 1008 Gnome Tetravex(DFS)

    题目链接 题意 : 将n*n个正方形进行排列,需要判断相邻的正方形的相邻三角形上边的数字是不是都相等. 思路 : 只知道是个深搜,一开始不知道怎么搜,后来看了题解才明白,就是说不是自己去搜,而是将给定 ...

  9. zoj 2734 Exchange Cards【dfs+剪枝】

    Exchange Cards Time Limit: 2 Seconds      Memory Limit: 65536 KB As a basketball fan, Mike is also f ...

随机推荐

  1. 每天一道LeetCode--118. Pascal's Triangle(杨辉三角)

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  2. 【Android】日常开发android.jar文件中十五个重要的包概述

    简述Android项目中android.jar文件里包含较为重要的15个系统编译后的class文件 android.app:提供高层的程序模型,提供基本的运行环境android.content:包含各 ...

  3. TSQL基础(二)

    over() 开窗函数 排名函数必须和over()一起使用,所以先了解over(). OVER 子句定义查询结果集内的窗口或用户指定的行集. 然后,开窗函数将计算窗口中每一行的值. 您可以将 OVER ...

  4. Win7显示隐藏文件,隐藏文件夹怎么显示?如何查看?

    隐藏文件技术是木马病毒传播最惯用的手法之一,它们利用大部分网友对基础操作的不熟悉特点,逃过用户的发现和检查,显示隐藏文件的标准设置方法大家都会使用,一旦隐藏问题与病毒木马结合起来,比如典型的autor ...

  5. jquery 评论等级(很差,差,一般,好,很好)代码

    可能标题没有说的太明白,这里先让大家看一下效果,以便让客官们了解小弟说的是什么... 看完效果后估计各位客官已经明白小弟说的是什么了吧,下面小弟就带大家看下代码 <style> .maxd ...

  6. minicsv库的编译错误与解决方案

    有一个项目需要写csv文件以呈现数据.Github上有一个关于csv的轻量级读写库minicsv,于是下载之.但是编译example时出现了以下问题: In file included from ex ...

  7. C++函数模板本质-学习入门

    template<typename T> void mySwap(T &a, T &b) { T c; c = a; a = b; b = c; } int main() ...

  8. Windows下bmp文件格式

    6.1 BMP文件格式 6.1.1 简介 位图文件(Bitmap-File,BMP)格式是Windows采用的图像文件存储格式,在Windows环境下运行的所有图像处理软件都支持这种格式.Window ...

  9. Adobe Photoshop CS4 Extended CS4 激活序列号

    Adobe Photoshop CS4 Extended CS4 激活序列号(SN):1330-1779-4488-2103-6954-09161330-1170-1002-7856-5023-077 ...

  10. ubuntu 14.04 nagios4+ndoutils2.0+centreon2.5.4配置

    ubuntu 14.04 nagios4+ndoutils2.0+centreon2.5.4(原创) 开发应用centreon是开源的IT监控软件,由法国人于2003年开发,最初名为Oreon,并于2 ...