Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

除了第一个样例,其他数据都正常,百思不得解啊啊。贴发代码

Posted by woodgo at 2016-08-15 19:11:56 on Problem 2686
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator