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 |
这个怎么能WA bellman做的- -好心人看看#include<iostream> using namespace std; #define MAX 202 #define Inf 100000000 double d[MAX]; double R[MAX][MAX], C[MAX][MAX]; double w(int a, int b) { return - ((d[a] - C[a][b]) * R[a][b] - d[a]); //加负号 则形成负环就是赚了 } int main() { int n, t, k; int i, j, p; int A, B; double RAB, CAB, RBA, CBA; double h; scanf("%d%d%d%lf", &n, &t, &k, &h); //cout << "<->" << endl; //getchar(); while(t --) { //cout << "---" << endl; getchar(); scanf("%d%d%lf%lf%lf%lf", &A, &B, &RAB, &CAB, &RBA, &CBA); //不能输入R[A][B] - -! R[A][B] = RAB; C[A][B] = CAB; R[B][A] = RBA; C[B][A] = CBA; } for(i = 1; i <= n; i ++) d[i] = Inf; d[k] = h; for(p = 1; p < n; p ++) for(i = 1; i <= n; i ++) for(j = 1; j <= n; j ++) { if(i == j) continue; if(d[i] < Inf && d[j] > d[i] + w(i, j)) { //printf("%lf\n", w(i, j)); d[j] = d[i] + w(i, j); //relax = 1; } } for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) if(d[j] > d[i] + w(i, j)) { printf("YES\n"); system("pause"); return 0; } } printf("NO\n"); system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator