博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1224 Free DIY Tour
阅读量:6271 次
发布时间:2019-06-22

本文共 3635 字,大约阅读时间需要 12 分钟。

Free DIY Tour

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2218    Accepted Submission(s): 717

Problem Description
Weiwei is a software engineer of ShiningSoft. He has just excellently fulfilled a software project with his fellow workers. His boss is so satisfied with their job that he decide to provide them a free tour around the world. It's a good chance to relax themselves. To most of them, it's the first time to go abroad so they decide to make a collective tour.
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 both
 
1
 and
N+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?
 

 

Input
The input will contain several cases. The first line is an integer T which suggests the number of cases. Then T cases follows. 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
For each case, your task is to output the maximal summation of interesting points Weiwei and his fellow workers can get through optimal DIYing and the optimal circuit. The format is as the sample. You may assume that there is only one optimal circuit.
 
Output a blank line between two cases.
 

 

Sample Input
2
3
0 70 90
4
1 2
1 3
2 4
3 4
3
0 90 70
4
1 2
1 3
2 4
3 4
 

 

Sample Output
CASE 1#
points : 90
circuit : 1->3->1
 
CASE 2#
points : 90
circuit : 1->2->1
 

 

Author
JGShining(极光炫影)
 

 

Source
 

 

Recommend
Ignatius.L
 
 
 
#include
#include
int map[120][120],visited[120];int ans[120],dp[120],pre[120];int main(){ //freopen("input.txt","r",stdin); int t,n,m,max; int cases=0; scanf("%d",&t); while(t--){ scanf("%d",&n); int i,j,k; for(i=1;i<=n;i++) scanf("%d",&dp[i]); memset(visited,0,sizeof(visited)); dp[n+1]=0; visited[1]=1; scanf("%d",&m); memset(map,0,sizeof(map)); int a,b; for(i=0;i
max){ max=dp[j]; k=j; } if(k!=0){ visited[i]=1; dp[i]+=max; pre[i]=k; } } printf("CASE %d#\npoints : %d\ncircuit : 1->",++cases,dp[n+1]); i=n+1;j=0; while(i!=1){ ans[j++]=i; i=pre[i]; } for(k=j-1;k>0;k--) printf("%d->",ans[k]); printf("1\n"); if(t!=0) printf("\n"); } return 0;}

 

转载地址:http://eblpa.baihongyu.com/

你可能感兴趣的文章
163 yum
查看>>
第三章:Shiro的配置——深入浅出学Shiro细粒度权限开发框架
查看>>
80后创业的经验谈(转,朴实但实用!推荐)
查看>>
让Windows图片查看器和windows资源管理器显示WebP格式
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
vim使用点滴
查看>>
embedded linux学习中几个需要明确的概念
查看>>
mysql常用语法
查看>>
Morris ajax
查看>>
【Docker学习笔记(四)】通过Nginx镜像快速搭建静态网站
查看>>
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
查看>>
<转>云主机配置OpenStack使用spice的方法
查看>>
java jvm GC 各个区内存参数设置
查看>>
[使用帮助] PHPCMS V9内容模块PC标签调用说明
查看>>
关于FreeBSD的CVSROOT的配置
查看>>
基于RBAC权限管理
查看>>
基于Internet的软件工程策略
查看>>
数学公式的英语读法
查看>>
留德十年
查看>>