为什么把这个题分到DP的分类中!!!
做完本题的感想:
1.仔细读题
2.注意数据的格式
/*
* POJ-1125 stockbroker grapevine
* mike-w
* 2011-10-23
* ------------------------------
* Note that the time taken to pass the message from person A to person B
* is not necessarily the same as the time taken to pass it from B to A,
* if such transmission is possible at all.
* -----------------------------
* FLOYD
* 郁闷...读数据出错了==||
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 111
#define INF 22222
int graph[SIZE][SIZE];
int dist[SIZE];
int N;
int main(void)
{
int i,j,k,c,t1,t2,min;
#ifndef ONLINE_JUDGE
freopen("t.in","r",stdin);
#endif
while(scanf("%d",&N),N)
{
for(i=0;i<=N;i++)
for(j=0;j<=N;j++)
if(i==j)
graph[i][j]=0;
else
graph[i][j]=INF;
/* read in data */
for(i=1;i<=N;i++)
{
scanf("%d",&c);
for(j=0;j<c;j++)
{
scanf("%d%d",&t1,&t2);
graph[i][t1]=t2;
}
}
/* FLOYD */
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
if(graph[j][i]<INF)
for(k=1;k<=N;k++)
if(graph[i][k]<INF && graph[j][i]+graph[i][k]<graph[j][k])
graph[j][k]=graph[j][i]+graph[i][k];
memset(dist,0,sizeof(dist));
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
if(graph[i][j]>dist[i])
dist[i]=graph[i][j];
min=1;
for(i=1;i<=N;i++)
if(dist[i]<dist[min])
min=i;
if(dist[min]==INF)
puts("disjoint");
else
printf("%d %d\n",min,dist[min]);
}
return 0;
}
本文深入探讨了动态规划(DP)在解决POJ-1125股票经纪葡萄藤问题中的作用,强调了仔细阅读题目、注意数据格式的重要性,并通过Floyd算法实现最优路径查找。实例分析帮助读者掌握DP方法在实际问题解决中的应用技巧。
534

被折叠的 条评论
为什么被折叠?



