54 条题解
-
0bonism LV 8 @ 2008-08-06 17:36:36
裸搜是王道!!!
我写了好多优化结果写败了!!!
把所有优化去掉,只剩一个DFS就AC了!!!水题啊~~~~!
-
02008-07-27 18:16:59@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms这不再是水题?
-
02008-07-26 17:15:49@
虽然题看上去不水,数据无论是在数量还是质量上都堪称一流shui
没有重边,反正我没考虑还是AC了,放心的做吧
-
02008-07-26 16:29:27@
最开始看成每个点只走一遍了....
结果过了3个点!
才发现是每条边只走一遍 -
02008-07-25 21:10:54@
晚了一步!!!!
-
02008-07-25 20:47:33@
!!!水
-
02008-07-25 14:34:48@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms天哪。。
还是照样的水。。只不过这题很阴。。
注意:你要找的是每边只走一次而不是每点只走一次。。
我就是这样被阴到的。。而且,这题数据暴弱,裸搜都能过!!而且不会出现重边!
-
02008-09-25 17:57:08@
注意重边,不过这题目貌似不用= = 直接搜
-
02008-07-25 09:36:26@
小号来刷题
-
02008-07-24 23:01:45@
先占个位置再做题
-
02008-07-24 22:20:49@
这不符合逻辑...过路费...
-
02008-07-24 21:44:51@
地板^^
-
-12016-12-24 21:14:34@
测试数据 #0: Accepted, time = 0 ms, mem = 612 KiB, score = 25
测试数据 #1: Accepted, time = 0 ms, mem = 612 KiB, score = 25
测试数据 #2: Accepted, time = 15 ms, mem = 612 KiB, score = 25
测试数据 #3: Accepted, time = 0 ms, mem = 612 KiB, score = 25
Accepted, time = 15 ms, mem = 612 KiB, score = 100感谢楼下dalao给的思路。。。
代码
#include<iostream> #include<iomanip> #include<cstring> #include<vector> #include<sstream> #include<algorithm> #include<string> #include<cstdio> #include<math.h> #include<map> #include<cctype> #include<queue> #include<functional> #include<set> #define min(a,b) (a)>(b)?(b):(a) #define Mem(a,b) memset((a),(b),sizeof((a))) using namespace std; const int maxn = 110; const int INF = 0x3f3f3f; struct Edge { int to, dist, money; Edge(){} Edge(int a, int b, int c) : to(a), dist(b), money(c){} }; vector<Edge> edges[maxn]; int d[maxn]; int n, m, t, v; int inq[maxn] = { 0 }; int visit[maxn][maxn] = { 0 }; void AddEdge(int from, int to, int time, int money){ edges[from].push_back(Edge(to, time, money)); edges[to].push_back(Edge(from, time, money)); } void init(){ for (int i = 1; i <= n; i += 1) { d[i] = INF; edges[i].clear(); } } void dijkstra(){ queue<int> Q; d[n] = 0; Q.push(n); while (!Q.empty()){ int u = Q.front(); Q.pop(); for (int i = 0; i < edges[u].size(); i += 1){ Edge& e = edges[u][i]; if (d[e.to] > d[u] + e.dist){ d[e.to] = d[u] + e.dist; if (!inq[e.to]){ Q.push(e.to); inq[e.to] = 1; } } } } } int ansm = -1, ansd = INF; void dfs(int u, int time, int money){ if (d[u] > (t - time) || money > v)//剪枝 return; if (u == n){//终止条件 if (ansm < money) ansm = money , ansd = time; else if (ansm == money && ansd > time) ansd = time; return; } for (int i = 0; i < edges[u].size(); i += 1) if(visit[u][edges[u][i].to] == 0){ visit[u][edges[u][i].to] = visit[edges[u][i].to][u] = 1; dfs(edges[u][i].to, time + edges[u][i].dist, money + edges[u][i].money); visit[u][edges[u][i].to] = visit[edges[u][i].to][u] = 0; } } int main() { scanf("%d %d %d %d", &n, &m, &t, &v); init(); for (int i = 0; i < m; i += 1){ int q, w, e, r; scanf("%d %d %d %d", &q, &w, &e, &r); AddEdge(q, w, e, r); } dijkstra(); dfs(1, 0, 0); printf("%d %d\n", ansd, v - ansm); return 0; }
-
-12016-11-17 17:13:15@
.
#include <cstdio>
#include <queue>
#include <algorithm>
using std::max;
using std::min;
struct edge{
int v,T,M;
edge *link;
};int n,m,top=0,TIME,MONEY;
edge graph[110]={0};
edge node[100*100*2+100];void add(int u,int v,int T,int M){
edge *l=&node[top++];
l->v=v,l->T=T,l->M=M;
l->link=graph[u].link;
graph[u].link=l;
}void build(){
scanf("%d%d%d%d",&n,&m,&TIME,&MONEY);
for(int i=1;i<=m;i++){
int u,v,T,M;
scanf("%d%d%d%d",&u,&v,&T,&M);
add(u,v,T,M);
add(v,u,T,M);
}
}//DFS
int vis[110][110]={0};
int bestT=999999999,bestM=0;void dfs(int u,int time,int money){
if(money>MONEY||time>TIME)
return;
if(u==n){
if(money>=bestM){
if(money==bestM)
bestT=min(bestT,time);
else
bestT=time;
bestM=money;
}
return;
}
edge *l=graph[u].link;
while(l){
int v=l->v;
if(!vis[u][v]){
vis[u][v]=vis[v][u]=1;
dfs(v,time+l->T,money+l->M);
vis[u][v]=vis[v][u]=0;
}
l=l->link;
}
}int main(){
freopen("in.txt","r",stdin);
build();
dfs(1,0,0);
printf("%d %d",bestT,MONEY-bestM);
return 0;
}