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,则我们可以计算 ...
随机推荐
- HDU 5807 Keep In Touch DP
Keep In Touch Problem Description There are n cities numbered with successive integers from 1 to n ...
- Java 之 多线程编程
1.线程: a.由来:单任务OS -- 多任务OS b.进程:每一个进程对应一个应用程序,分配独立内存空间 c.线程:线程是进程内部的一个独立的执行分支 d.特点:共享内容地址空间,切换成本更低 2. ...
- Socket编程基础知识
端口号常识: 端口号被从1 开始分配. 通常端口号超出255 的部分被本地主机保留为私有用途. 1到255 之间的号码被用于远程应用程序所请求的进程和网络服务. 每个网络通信循环地 ...
- MOB 短信验证
工具/原料 Android Studio mob SDK中的jar 和.so文件 方法/步骤 1 把3个jar 放入libs 并添加依赖 在项目的build.gradle里面 在你的项 ...
- express-3 最佳实践
版本控制 版本控制有以下益处: 文档: 能够回溯项目的历史,回顾所做的决策及组件的开发顺序,可形成宝贵的文档.记录项目的历史是十分有价值的. 归属: 团队工作,分工清晰,节省沟通成本. 试验: 你可以 ...
- DOM--4 响应用户操作和事件(1)
简介 事件:事件并不是以"on"开头的.例如,onclick引用的是一个对象的属性,click才是事件. 事件侦听器:当指定的事件发生时会执行的函数或方法. 事件注册:为DOM元素 ...
- Visual Studio 设置 Inherited include Directories
在用Visual Studio进行开发的时候,避免不了要使用一些常用的第三方提供的库.如果是一次两次设置还能让人忍受,但是如果要写很多项目的话,设置这些库真的很让人头疼.不过Visual Studio ...
- 【转】Python yield 使用浅析
转载地址: www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ Python yield 使用浅析 初学 Python 的开发者经 ...
- SPOJ TSUM Triple Sums(FFT + 容斥)
题目 Source http://www.spoj.com/problems/TSUM/ Description You're given a sequence s of N distinct int ...
- iOS学习30之UITableView编辑
1. UITableView编辑 1> UITableView 编辑流程 2> UITableView 编辑步骤(四步) ① 第一步 : 让 TableView 处于编辑状态(在按钮点击事 ...