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 |
仔细看了下枚举的方法 然后自己做1A- -#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN=105, infi=1<<30; int map[MAXN][MAXN], d[MAXN], rank[MAXN], p[MAXN], x, n; bool used[MAXN]; void dijkstra(int st,int ed) { int i, j; memset(used,0,sizeof(used)); for(i=1;i<=n;i++) { if(rank[i]<st||rank[i]>ed) used[i]=true; d[i]=infi; } d[1]=0; for(i=1;i<n;i++) { int minv=infi, k; for(j=1;j<=n;j++) { if(!used[j]&&d[j]<minv) { minv=d[j]; k=j; } } if(minv==infi) break; used[k]=true; for(j=1;j<=n;j++) { if(!used[j]&&d[k]+map[k][j]<d[j]) { d[j]=d[k]+map[k][j]; } } } } int main() { int m, i, j, a, b; while(scanf("%d%d",&m,&n)!=EOF) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) map[i][j]=infi; for(i=1;i<=n;i++) { scanf("%d%d%d",&p[i],&rank[i],&x); { while(x--) { scanf("%d%d",&a,&b); map[i][a]=b; } } } int solv=infi; for(i=rank[1]-m;i<=rank[1];i++) { dijkstra(i,i+m); for(j=1;j<=n;j++) solv=min(solv,p[j]+d[j]); } printf("%d\n",solv); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator