标签:des style http color strong os
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 35968 | Accepted: 10314 |
Description
Input
Output
Sample Input
1 4 10000 3 2 2 8000 3 5000 1000 2 1 4 200 3000 2 1 4 200 50 2 0
Sample Output
5250
Source
AC代码:
#include<iostream> using namespace std; int m,n; int dis[105]; int G[105][105]; int p[105],r[105]; void dij(int st,int ed){ int vis[105]; for(int i=2;i<=n;i++){ vis[i]=0; dis[i]=G[1][i]; if(r[i]<st || r[i]>ed){ vis[i]=1; dis[i]=999999; } } dis[1]=0; vis[1]=1; for(int i=1;i<n;i++){ int v,min=999999; for(int j=1;j<=n;j++){ if(!vis[j] && dis[j]<min){ min=dis[j]; v=j; } } if(min==999999) break; vis[v]=1; for(int j=1;j<=n;j++){ if(!vis[j] && dis[j]>min+G[v][j]) dis[j]=min+G[v][j]; } } } int main(){ while(cin>>m>>n){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i==j) G[i][j]=0; else G[i][j]=999999; for(int i=1;i<=n;i++){ int t; cin>>p[i]>>r[i]>>t; for(int j=1;j<=t;j++){ int v,price; cin>>v>>price; G[i][v]=price; } } int ans=999999; for(int i=r[1]-m;i<=r[1];i++){ dij(i,i+m); //枚举等级范围 for(int j=1;j<=n;j++){ if(ans>dis[j]+p[j]){ ans=dis[j]+p[j]; } } } cout<<ans<<endl; } return 0; }
poj 1062 (dij最短路径),布布扣,bubuko.com
标签:des style http color strong os
原文地址:http://blog.csdn.net/my_acm/article/details/38011213