Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
状态压缩裸题#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <sstream> #include <iomanip> using namespace std; typedef long long LL; const double INF=0x4fffffff; const double EXP=1e-5; const int MS=10; const int SIZE=31; double dp[1<<MS][SIZE]; int edges[SIZE][SIZE]; int cnt[MS]; int start,final,tickets,citys,edge; void solve() { for(int i=0;i<(1<<tickets);i++) fill(dp[i],dp[i]+SIZE,INF); dp[(1<<tickets)-1][start-1]=0; double res=INF; for(int i=(1<<tickets)-1;i>=0;i--) { res=min(res,dp[i][final-1]); for(int u=0;u<citys;u++) { for(int j=0;j<tickets;j++) { if((i>>j)&1) { for(int v=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]); } } } } if(res+EXP>=INF) printf("Impossible\n"); else printf("%.3lf\n",res); } int main() { while(scanf("%d%d%d%d%d",&tickets,&citys,&edge,&start,&final)==5&&tickets) { for(int i=0;i<tickets;i++) { scanf("%d",&cnt[i]); } memset(edges,-1,sizeof(edges)); for(int i=0;i<edge;i++) { int x,y,z; scanf("%d%d%d",&x,&y,&z); edges[x-1][y-1]=edges[y-1][x-1]=z; } solve(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator