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 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的更多相关文章
- zoj 3620 Escape Time II
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4744 Escape Time II Time Limit: 2 Seconds ...
- ZOJ 3631 Watashi's BG DFS
J - Watashi's BG Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Subm ...
- ZOJ 3332 Strange Country II
Strange Country II Time Limit: 1 Second Memory Limit: 32768 KB Special Judge You want to v ...
- zoj 3356 Football Gambling II【枚举+精度问题】
题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...
- ZOJ 4124 拓扑排序+思维dfs
ZOJ - 4124Median 题目大意:有n个元素,给出m对a>b的关系,问哪个元素可能是第(n+1)/2个元素,可能的元素位置相应输出1,反之输出0 省赛都过去两周了,现在才补这题,这题感 ...
- ZOJ 1002 Fire Net(dfs)
嗯... 题目链接:https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364501 这道题是想出来则是一道很简单的dfs: 将一 ...
- ZOJ 3644 Kitty's Game dfs,记忆化搜索,map映射 难度:2
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 从点1出发,假设现在在i,点数为sta,则下一步的点数必然不能是sta的 ...
- ZOJ 1008 Gnome Tetravex(DFS)
题目链接 题意 : 将n*n个正方形进行排列,需要判断相邻的正方形的相邻三角形上边的数字是不是都相等. 思路 : 只知道是个深搜,一开始不知道怎么搜,后来看了题解才明白,就是说不是自己去搜,而是将给定 ...
- zoj 2734 Exchange Cards【dfs+剪枝】
Exchange Cards Time Limit: 2 Seconds Memory Limit: 65536 KB As a basketball fan, Mike is also f ...
随机推荐
- xml使用系统整理
1. 认识xml 可扩展标记语言,一种用于标记电子文档使其具有结果性的标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 2. 和超文本标记语言区别 2.1 ...
- 设置win7任务栏显示标题,而不显示缩略图
win7系统的任务栏可以显示桌面缩略图,这是非常好的一个功能,但是有时候我们希望只显示标题,如下所示 怎样设置呢?只要在桌面上的计算机图标上面“右键”,选择“属性”,在弹出的窗口选择“高级系统设置”, ...
- asterisk 语音文件转换
Centos wav to sln sox foo-in.wav -t raw -r 8000 -s -2 -c 1 foo-out.sln 当前目录下所有语音wav文件 转换成sln for a i ...
- ios开发入门篇(二):Objective-C的简单语法介绍
一:面向对象的思想 objective-c与C语言的编程思想不同,C语言是面向过程的编程,而objective-c则是面向对象的编程,所谓面向对象,我个人的理解,就是抽象.将具有一定共同点的实物抽象成 ...
- [Bootstrap]全局样式(一)
页面必须设置为html5文档类型 <!DOCTYPE html> <html lang="zh-CN"> ... </html> 适应移动设备 ...
- main与进程 线程
你起一个CS游戏,这上CS游戏在操作系统中就是一个进程. 但是这个游戏一边在打枪,一边人在走动,一边还有音乐 ,打枪 , 走动 , 音乐 等都是一些线程. 线程不是由进程决定了. 也就是说:你在操作系 ...
- Linux 小记录
<1>bzero 原型:extern void bzero(void *s, int n);用法:#include <string.h> 功能:置字节字符串s的前n个字节为零. ...
- 使用git的正确姿势
1.Windows上安装git:从https://git-for-windows.github.io下载msysgit. 2.linux(Debian或Ubuntu)安装git:sudo apt-ge ...
- 利用mysqld_multi启动管理多实例
利用mysqld_multi启动管理多实例 官方管理多实例的一个脚本peer #将之前的目录清空 [root@mysql01 mysql]# tree /data/mysql/ /data/mysql ...
- 【Sqlserver】修改数据库表中的数据:对缺失的数据根据已有的数据进行修补
1 --查询时间范围内的数据 select * from dbo.point where wtime >'2014-05-01 23:59:59' and wtime< '2014-05- ...