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 |
Re:DFS+等级范围枚举AC留爪...顺附几组测试数据...In Reply To:Re:DFS+等级范围枚举AC留爪...顺附几组测试数据... Posted by:clegend at 2011-03-06 16:34:48 > >无奈啊 #include <iostream> using namespace std; #define MAX 105 int dis[MAX][MAX],level[MAX]; int m,n; int dijkstra(int r) { int value[MAX],visit[MAX],i,j; memcpy(value,dis[0],MAX); memset(visit,0,sizeof(visit)); visit[0]=1;//标记起始节点 for (i=0;i<n;i++) { int min=-1; int line; for (j=1;j<=n;j++) { if (!visit[j]&&level[j] <= r && level[j] >= r-m)//j点未访问过,且在权限内 { if (min==-1||value[j]<min) { min=value[j]; line=j; } } } if (line==1) break; if (min!=-1) { for (j=1;j<=n;j++) { if (value[j]>min+dis[j][line]&&dis[j][line]!=-1&&level[j] <= r && level[j] >= r-m) value[j]=min+dis[j][line]; } visit[line]=1; } else break; } return value[1]; } int main() { int i,j; int num,temp; cin>>m>>n; memset(dis,-1,sizeof(dis));//-1表示不可达 for (i=1;i<=n;i++) { cin>>dis[0][i]>>level[i]>>num; for (j=0;j<num;j++) { cin>>temp; cin>>dis[i][temp]; } } int min=-1; for (i=level[1]+m;i>0&&i>=level[1];i--) { temp=dijkstra(i); if (min==-1||temp<min) min=temp; } cout<<min<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator