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<algorithm> #include<cstring> #include<stdio.h> using namespace std; #define maxn 8 #define maxm 40 #define inf 0x3f3f3f3f double dp[1 << maxn][maxm]; int d[maxm][maxm]; int ticket[maxn]; int n, m, p; int st, target; //solve double rec(int S, int v){ if (dp[S][v] >= 0) return dp[S][v]; if (v == target) return dp[S][v] = 0; double res = inf; for (int u = 1; u <= m; u++){ if (d[u][v] == -1) continue; else for (int i = 0; i<n; i++){ if (!(S >> i) & 1){ res = min(res, rec(S | (1 << i), u) + d[v][u] * 1.0 / ticket[i]); } } } return dp[S][v] = res; cout << res << endl; } int main(){ while ((scanf("%d%d%d%d%d", &n, &m, &p, &st, &target) == 5)){ //while(cin>>n>>m>>p>>st>>target){ memset(d, -1, sizeof(d)); memset(dp, -1, sizeof(dp)); if (!m&&!n&&!p&&!st&&!target) break; for (int i = 0; i<n; i++) scanf("%d", ticket + i); for (int i = 0; i<p; i++){ int u, v, c; scanf("%d%d%d", &u, &v, &c); d[u][v] = d[v][u] = c; } double ans = rec(0, st); if (ans == inf)cout << "Impossible" << endl; else printf("%.6f\n", ans); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator