hdu1224
来源:互联网 发布:淘宝香港订单怎么发货 编辑:程序博客网 时间:2024/06/05 10:25
Free DIY Tour
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1001 Accepted Submission(s): 331
The tour company shows them a new kind of tour circuit - DIY circuit. Each circuit contains some cities which can be selected by tourists themselves. According to the company's statistic, each city has its own interesting point. For instance, Paris has its interesting point of 90, New York has its interesting point of 70, ect. Not any two cities in the world have straight flight so the tour company provide a map to tell its tourists whether they can got a straight flight between any two cities on the map. In order to fly back, the company has made it impossible to make a circle-flight on the half way, using the cities on the map. That is, they marked each city on the map with one number, a city with higher number has no straight flight to a city with lower number.
Note: Weiwei always starts from Hangzhou(in this problem, we assume Hangzhou is always the first city and also the last city, so we mark Hangzhou both1 andN+1), and its interesting point is always 0.
Now as the leader of the team, Weiwei wants to make a tour as interesting as possible. If you were Weiwei, how did you DIY it?
Each case will begin with an integer N(2 ≤ N ≤ 100) which is the number of cities on the map.
Then N integers follows, representing the interesting point list of the cities.
And then it is an integer M followed by M pairs of integers [Ai, Bi] (1 ≤ i ≤ M). Each pair of [Ai, Bi] indicates that a straight flight is available from City Ai to City Bi.
Output a blank line between two cases.
230 70 9041 21 32 43 430 90 7041 21 32 43 4
CASE 1#points : 90circuit : 1->3->1CASE 2#points : 90circuit : 1->2->1
/*起初以为这题是用Floyd算法,便起手尝试着做,Floyd的路径保存和输出又不懂,结果一直WA。。
后面才知道原来只要简单的DP就可以求出最长(兴趣点最高)路径,需要注意的还是路径的输出,DP时用pre[x]保存访问顶点x时的前驱,这样就OK了。
if (map[j][i]!=-1&& dp[j] + map[j][i] > dp[i] ) //状态转移要判断从j到i是否可以走通
dp[i] = dp[j] + map[j][i];*/
输出有点不明白!!!!!
#include <stdio.h>
#include <string.h>
int map[110][110];
int dp[110];
int pre[110];
int inst[110];
void output( int x )
{
if ( x == -1)
return;
output(pre[x]);
printf("%d->",x);
}
int main()
{
int T,n,m;
int i,j,k;
int cases = 1;
scanf("%d",&T);
while ( T-- )
{
scanf("%d",&n);
memset(map,-1,sizeof(map));
memset(dp,0,sizeof(dp));
for ( i = 1; i <= n; i++)
scanf("%d",&inst[i]);
inst[n+1] = 0;
scanf("%d",&m);
for ( k = 1; k <= m; k++)
{
scanf("%d%d",&i,&j);
map[i][j] = inst[j];
}
pre[1] = -1;
for ( i = 1; i <= n + 1; i++)
for ( j = 1; j < i; j++)
{
if (map[j][i]!=-1&& dp[j] + map[j][i] > dp[i] )
{
dp[i] = dp[j] + map[j][i];
pre[i] = j;
}
}
if ( cases>1 )printf("\n");
printf("CASE %d#\n",cases++);
printf("points : %d\n",dp[n+1]);
printf("circuit : ");
output(pre[n+1]);
printf("1\n");
}
return 0;
}
- hdu1224
- hdu1224
- hdu1224
- hdu1224
- hdu1224
- hdu1224
- HDU1224
- hdu1224
- HDU1224 动态规划
- HDU1224 Free DIY Tour
- HDU1224 Free DIY Tour
- hdu1224 Free DIY Tour
- HDU1224-Free DIY Tour
- hdu1224 spfa 最大路
- HDU1224 Free DIY Tour 【SPFA】
- hdu1224解题报告(dfs)
- hdu1224 Free DIY Tour--DP
- hdu1224 dp动态规划+图论
- 解决了Erlang的UTF-8转Unicode中文显示问题
- display:none 和visibility:hidden的区别
- Openfire源代码调试、编译开发环境
- SQL Server 无法生成 FRunCM 线程
- HDU 3905 Sleeping
- hdu1224
- openfire 的源代码分析 clint-to-server
- 技术发展阶段
- static_cast
- 关于struts2中的拦截器和登陆验证
- svn重复Lock,后来好了,有点晕,但是记录一下吧。
- linux下安装oracle 10g记录
- [Visual C++系列]1.4 利用MFC进行开发的通用方法介绍
- [Visual C++系列] 1.5 MFC中常用类,宏,函数介绍