hdu 1142 A Walk Through the Forest Dijkstra+记忆搜索
来源:互联网 发布:淘宝第一商城 编辑:程序博客网 时间:2024/04/27 23:46
#include<iostream>using namespace std;const int MAX=2147483647;int n,m;int t1,t2,len;int map[1005][1005];int ans[1005];int isvisit[1005];int answer;void Dijkstra();int DFS(int k);int main(){while(cin>>n,n){answer=0;memset(isvisit,-1,sizeof(isvisit));for(int i=1;i<=n;i++){ans[i]=MAX;for(int j=1;j<=n;j++){map[i][j]=MAX;}}cin>>m;for(i=0;i<m;i++){cin>>t1>>t2>>len;if(map[t1][t2]>len)map[t1][t2]=map[t2][t1]=len;}Dijkstra();//for(i=1;i<=n;i++)//{//cout<<ans[i]<<endl;//}cout<<DFS(1)<<endl;}return 0;}void Dijkstra(){int visit[1005]={0};int k;ans[2]=0;for(int i=1;i<=n;i++){k=-1;for(int j=1;j<=n;j++){if(!visit[j] && ( k==-1 || ans[j]<ans[k]) )k=j;}visit[k]=1;for(j=1;j<=n;j++){if(!visit[j] && ans[j]>ans[k]+map[k][j] && map[k][j]!=MAX)ans[j]=ans[k]+map[k][j];}}}int DFS(int k){int temp=0;if(isvisit[k]!=-1)return isvisit[k];if(k==2){return 1;}for(int i=1;i<=n;i++){if(map[k][i]!=MAX && ans[k]>ans[i])temp+=DFS(i);}isvisit[k]=temp;return temp;}
- hdu 1142 A Walk Through the Forest Dijkstra+记忆搜索
- hdu 1142 A Walk Through the Forest (Dijkstra + 记忆化搜索)
- HDU 1142 A Walk Through the Forest (Dijkstra + 记忆化搜索 好题)
- HDU 1142 A Walk Through the Forest (记忆化搜索+Dijkstra算法)
- HDU 1142 A Walk Through the Forest (dijkstra+记忆化搜索)
- HDU 1142 A Walk Through the Forest【记忆化搜索+最短路Dijkstra算法】
- HDU 1142 A Walk Through the Forest (dijkstra+记忆化搜索)
- 【Dijkstra+DFS(记忆化)】hdu 1142 A Walk Through the Forest(外:hdu 1428)
- HDU 1142 A Walk Through the Forest(图论Dijkstra)
- hdu 1142 A Walk Through the Forest Dijkstra
- HDU-1142-A Walk Through the Forest(Dijkstra+dfs)
- hdu 1142 A Walk Through the Forest (最短路 + 记忆化搜索)
- hdu 1142 A Walk Through the Forest(spfa求最短路+记忆化搜索)
- HDU 1142 A Walk Through the Forest (SPFA+记忆化搜索)
- 【HDU】1142 A Walk Through the Forest 最短路+记忆化搜索
- HDU 1142 A Walk Through the Forest 最短路+记忆搜索
- HDU--1142--A Walk Through the Forest--深广搜/DP/最短路径/记忆化搜索
- hdu-1142-A Walk Through the Forest-最短路+记忆化搜索
- hdu 3172 Virtual Friends 字典树+并查集
- 编程之美2.4——1的数目
- VIM
- Rails源代码研读之ActiveRecord研读
- myeclipse智能感知
- hdu 1142 A Walk Through the Forest Dijkstra+记忆搜索
- 安装DOS中断处理程序
- sqlplus / as sysdba ora-01031: insufficient privileges
- 那些年,为毕业设计的执着
- MyEclipse相关用法介绍
- FreeMarker如果遇到正则表达式的时候会出现的bug
- 再谈“事件驱动”
- 十招教你从程序员转向企业家
- 编程之美2.3——发帖水王(+扩展)