Traveling by Stagecoach
DP[S][V] from the source point to V, the state is the minimum value of s,v. The For loop enumeration is OK.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <stack> One#include <queue> A#include <sstream> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; - Const Doubleinf=0x4fffffff; - Const Doubleexp=1e-5; - Const intms=Ten; + Const intSize= to; - + Doubledp[1<<MS] [SIZE]; A at intEdges[size][size]; - intCnt[ms]; - - intStart,final,tickets,citys,edge; - - voidSolve () in { - for(intI=0;i< (1<<tickets); i++) toFill (dp[i],dp[i]+size,inf); +dp[(1<<tickets)-1][start-1]=0; - Doubleres=INF; the for(intI= (1<<tickets)-1; i>=0; i--) * { $Res=min (res,dp[i][final-1]);Panax Notoginseng for(intu=0; u<citys;u++) - { the for(intj=0; j<tickets;j++) + { A if((I>>J) &1) the { + for(intv=0; v<citys;v++) - if(edges[u][v]>=0) $dp[i-(1<<J)][v]=min (dp[i-(1<<J)][v],dp[i][u]+Double(Edges[u][v])/cnt[j]); $ } - } - } the } - if(res+exp>=INF)Wuyiprintf"impossible\n"); the Else -printf"%.3lf\n", res); Wu } - About intMain () $ { - while(SCANF ("%d%d%d%d%d", &tickets,&citys,&edge,&start,&final) = =5&&tickets) - { - A for(intI=0; i<tickets;i++) + { thescanf"%d",&cnt[i]); - } $memset (edges,-1,sizeof(edges)); the for(intI=0; i<edge;i++) the { the intx, y, z thescanf"%d%d%d",&x,&y,&z); -edges[x-1][y-1]=edges[y-1][x-1]=Z; in } the solve (); the } About return 0; the}
Traveling by Stagecoach state Compression Bare Topic