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 |
我用最普通的最短路+枚举,上面的数据都过了,一直WRONG ANSWER。。In Reply To:Re:DFS+等级范围枚举AC留爪...顺附几组测试数据... Posted by:agralol at 2010-08-24 19:51:12 #include<stdio.h> #include<string.h> #define INF 1<<30 int w[101][101],p[101],d[101],sta[101],v[101],de[101]; int main() { int M,N,i,j,k; scanf("%d %d",&M,&N); for(i=1;i<=N;i++) { for(j=1;j<=N;j++) w[i][j]=INF; } int t1,t2,num,n,price; for(i=1;i<=N;i++) { scanf("%d %d %d",&p[i],&sta[i],&num); for(j=0;j<num;j++) { scanf("%d %d",&n,&price); w[i][n]=price; } } int ans=INF; int bottom=sta[1]-M>=0?sta[1]-M:0; for(k=bottom;k<=sta[1];k++) { d[1]=0; for(i=2;i<=N;i++) d[i]=INF; t1=k;t2=t1+M; int s=N; memset(v,0,sizeof(v)); memset(de,1,sizeof(de)); for(i=2;i<=N;i++) if(sta[i]<t1||sta[i]>t2) {de[i]=0;s--;} for(i=1;i<=s;i++) { int x,m=INF; for(j=1;j<=N;j++) if(de[j]&&!v[j]&&d[j]<=m) m=d[x=j]; v[x]=1; for(j=1;j<=N;j++) if(de[j]&&d[j]>d[x]+w[x][j]) d[j]=d[x]+w[x][j]; } for(i=1;i<=N;i++) if(de[i]&&d[i]+p[i]<ans) ans=d[i]+p[i]; } printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator