Escape Time II
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3620
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), 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.
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
HINT
题意
给你个无向边带权图,让你在时间内从s走到e,拿的糖果最多,然后让你输出,拿了多少个糖果
题解:
数据范围太小了,直接暴力搜索就好了……
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200001 #define mod 10007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar(‘0‘);puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** struct node { int x,y; }; int n,m,t; int s,en; int jew[15]; int vis[20][20]; int ans; int g[20][20]; void init() { ans=0; memset(jew,0,sizeof(jew)); memset(g,0,sizeof(g)); memset(vis,0,sizeof(vis)); } void dfs(int po,int tt,int num) { if(po==en&&tt<=t) ans=max(ans,num); for(int i=0;i<n;i++) { if(!vis[po][i]&&g[po][i]&&tt+g[po][i]<=t) { int tmp=jew[i]; vis[po][i]=1; jew[i]=0; dfs(i,tt+g[po][i],num+tmp); jew[i]=tmp; vis[po][i]=0; } } } int main() { //freopen("test.txt","r",stdin); while(scanf("%d%d%d",&n,&m,&t)!=EOF) { init(); s=read(),en=read(); for(int i=0;i<n;i++) jew[i]=read(); for(int i=1;i<=m;i++) { int a=read(),b=read(),c=read(); g[a][b]=c,g[b][a]=c; } int tmp=jew[s]; jew[s]=0; dfs(s,0,tmp); printf("%d\n",ans); } }