HDU1224 DP
Free DIY Tour
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6227 Accepted Submission(s): 2013
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?
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.
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.
/*
到达每一个城市的最大价值取决于能够到达他的城市中价值较大的那个再加上它本身,记录路径load[i]存入能够到达i
的最优的那个城市最后输出load[i],load[load[i]]........
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
int t,n,m;
int dp[];
int val[];
int main()
{
int a,b;
scanf("%d",&t);
for(int h=;h<=t;h++)
{
stack<int>q[];
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&val[i]);
val[n+]=;
scanf("%d",&m);
while(m--)
{
scanf("%d%d",&a,&b);
q[b].push(a);
}
memset(dp,,sizeof(dp));
int load[];
for(int i=;i<=n+;i++)
{
if(q[i].empty())
continue;
while(!q[i].empty())
{
int father=q[i].top();
q[i].pop();
if(dp[i]<dp[father]+val[i])
{
dp[i]=dp[father]+val[i];
load[i]=father;
}
} }
if(h!=)
printf("\n");
printf("CASE %d#\n",h);
printf("points : %d\ncircuit : ",dp[n+]);
int k=,kk=n+,lload[];
while(kk!=)
{
lload[k++]=load[kk];
kk=load[kk];
}
for(int i=k-;i>=;i--)
{
printf("%d->",lload[i]);
}
printf("1\n");
}
return ;
}
HDU1224 DP的更多相关文章
- hdu1224 dp(dp + 栈/父亲数组记录路径)
题意:给定 n 个城市的有趣度,并给出可以从那些城市飞到那些城市.其中第一个城市即起始城市同样也作为终点城市,有趣度为 0,旅行途中只允许按有趣度从低到高旅行,问旅行的有趣度最大是多少,并输出旅行路径 ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
- AEAI DP V3.7.0 发布,开源综合应用开发平台
1 升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...
- AEAI DP V3.6.0 升级说明,开源综合应用开发平台
AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- [斜率优化DP]【学习笔记】【更新中】
参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...
- BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9812 Solved: 3978[Submit][St ...
- px、dp和sp,这些单位有什么区别?
DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...
随机推荐
- javascript中时间的手动创建date的方式
new Date("month dd,yyyy hh:mm:ss"); new Date("month dd,yyyy"); new Date(yyyy,mth ...
- 安装PIL
本来直接pip install PIL的,一直说找不到对应的版本,在廖雪峰老师的博客里发现原来PIL只更新到pytyon 2.7 后来就只有Pillow了,而我的版本是2.7.9 用的时候直接from ...
- 【maven 报错】maven项目执行maven install时报错Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)
在使用maven新建的web项目中,执行 执行如上的这两个操作,报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-co ...
- 30分钟LINQ教程(转)
在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前, 我们在声明一个变量的时候, 总是要为一个变量指定他的类型 甚至在fore ...
- react-redux(2)
中间件 机制: 建立一个store.dispatch的链条,每个middleware是链条中的一个环节,传入的action对象逐步处理,直到最后出来是Javascript Plain Object; ...
- 数据库查询Database中的表
public class UserDA { SqlConnection conn; SqlCommand cmd; public UserDA(Use uuu) { conn =new SqlConn ...
- Something about "for"
For语句引导了一个循环语句,格式for(::),例for(int i=0;i<100;i++).类似于if()括号的作用for()括号如同if()括号一样也是一个boolean型.int i= ...
- Swift3.0语言教程字符串与URL的数据转换与自由转换
Swift3.0语言教程字符串与URL的数据转换与自由转换 Swift3.0语言教程字符串与URL的数据转换 Swift3.0语言教程字符串与URL的数据转换与自由转换,字符串中的字符永久保存除了可以 ...
- ajax上传后用超链接展示无法下载问题
ajax插件上传后用超链接展示出来,但是点击超链接无法下载,最后发现是上传文件名为中文在作怪,于是修改了tomcat配置文件server.xml中的 <Connector port=" ...
- 百度地图API使用记录
用户数据图层的总教程: 就是把用户数据存到LBS云里面,应用从云里面读数据 http://developer.baidu.com/map/jsdevelop-9.htm 上传数据的地方: http:/ ...