zoj 3620 Escape Time II dfs
2016-07-01 19:59
316 查看
题目链接:
题目
Escape Time IITime 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.样例
input3 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; }
相关文章推荐
- [na]数据包由于isp不稳定丢包-seq&ack
- Android Studio "佛祖保佑 永无bug" 注释模板设置详解(仅供娱乐)
- python之简单排序和随机整数
- HTMLParser使用详解(2)- Node内容
- 文件描述符
- C++中const用法总结
- 51nod 1396 还是01串
- EasyUI combogrid 更新查询参数 queryParams 重新加载
- mysql安装出现error Nr.1045
- php.ini-development和php.ini-production的区别
- java基础
- java JFrame 关闭窗口时确认
- Android 开发者选项详述
- LeetCode 第 371 题 (Sum of Two Integers)
- LeetCode 第 371 题 (Sum of Two Integers)
- 【BZOJ-3638&3272&3267&3502】k-Maximum Subsequence Sum 费用流构图 + 线段树手动增广
- Markdown 语法说明 (简体中文版) / (点击查看快速入门)
- CentOS下MySQL忘记root密码解决方法【转载】
- MD5 Message Digest Algorithm MD5(中文名为消息摘要算法第五版)
- hdu 4986 Little Pony and Alohomora Part I(找规律,欧拉常数)