UVA 590 二十一 Always on the run
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
System Crawler (2015-08-26)
Description
Screeching tires. Searching lights. Wailing sirens. Police cars everywhere. Trisha Quickfinger did it again! Stealing the `Mona Lisa' had been more difficult than planned, but being the world's best art thief means expecting the unexpected. So here she is, the wrapped frame tucked firmly under her arm, running to catch the northbound metro to Charles-de-Gaulle airport.
But even more important than actually stealing the painting is to shake off the police that will soon be following her. Trisha's plan is simple: for several days she will be flying from one city to another, making one flight per day. When she is reasonably sure that the police has lost her trail, she will fly to Atlanta and meet her `customer' (known only as Mr. P.) to deliver the painting.
Her plan is complicated by the fact that nowadays, even when you are stealing expensive art, you have to watch your spending budget. Trisha therefore wants to spend the least money possible on her escape flights. This is not easy, since airlines prices and flight availability vary from day to day. The price and availability of an airline connection depends on the two cities involved and the day of travel. Every pair of cities has a `flight schedule' which repeats every few days. The length of the period may be different for each pair of cities and for each direction.
Although Trisha is a good at stealing paintings, she easily gets confused when booking airline flights. This is where you come in.
Input
The input file contains the descriptions of several scenarios in which Trisha tries to escape. Every description starts with a line containing two integers n and k. n is the number of cities through which Trisha's escape may take her, and k is the number of flights she will take. The cities are numbered , where 1 is Paris, her starting point, and n is Atlanta, her final destination. The numbers will satisfy
and
.
Next you are given n(n - 1) flight schedules, one per line, describing the connection between every possible pair of cities. The first n - 1 flight schedules correspond to the flights from city 1 to all other cities ( ), the next n - 1 lines to those from city 2 to all others (
), and so on.
The description of the flight schedule itself starts with an integer d, the length of the period in days, with . Following this ared non-negative integers, representing the cost of the flight between the two cities on days
. A cost of 0 means that there is no flight between the two cities on that day.
So, for example, the flight schedule ``3 75 0 80'' means that on the first day the flight costs 75, on the second day there is no flight, on the third day it costs 80, and then the cycle repeats: on the fourth day the flight costs 75, there is no flight on the fifth day, etc.
The input is terminated by a scenario having n = k = 0.
Output
For each scenario in the input, first output the number of the scenario, as shown in the sample output. If it is possible for Trisha to travel kdays, starting in city 1, each day flying to a different city than the day before, and finally (after k days) arriving in city n, then print `` The best flight costs x.'', where x is the least amount that the k flights can cost.
If it is not possible to travel in such a way, print ``No flight possible.''.
Print a blank line after each scenario.
Sample Input
3 6
2 130 150
3 75 0 80
7 120 110 0 100 110 120 0
4 60 70 60 50
3 0 135 140
2 70 80
2 3
2 0 70
1 80
0 0
Sample Output
Scenario #1
The best flight costs 460. Scenario #2
No flight possible.
Miguel A. Revilla
1998-03-10
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int dp[][];
int fly[][][];
int main()
{
int n,k,ca=;
int i,j,l;
while(scanf("%d %d",&n,&k)!=EOF)
{
if(n== && k==)
break;
memset(fly,,sizeof(fly));
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(j==i)
continue;
scanf("%d",&fly[i][j][]);
for(l=;l<=fly[i][j][];l++)
{
scanf("%d",&fly[i][j][l]);
}
}
} /*for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%d:",fly[i][j][0]);
for(l=1;l<=k;l++)
printf("%d ",fly[i][j][l]);
printf("\n");
}
printf("\n");
}*/ memset(dp,-,sizeof(dp));
dp[][]=;
for(l=;l<=k;l++)
{
for(i=;i<=n;i++)
{
if(dp[l-][i]!=-)
{
for(j=;j<=n;j++)
{
if(fly[i][j][]==)
continue;
int ll;
if(l%(fly[i][j][])==)
ll=fly[i][j][];
else
ll=l%fly[i][j][];
if(fly[i][j][ll]!=)
{
if(dp[l][j]==-)
dp[l][j]=dp[l-][i]+fly[i][j][ll];
else
dp[l][j]=min(dp[l][j],dp[l-][i]+fly[i][j][ll]);
}
}
}
}
} if(dp[k][n]!=-)
printf("Scenario #%d\nThe best flight costs %d.\n\n",ca++,dp[k][n]);
else
printf("Scenario #%d\nNo flight possible.\n\n",ca++);
}
return ;
}
UVA 590 二十一 Always on the run的更多相关文章
- 无废话ExtJs 入门教程二十一[继承:Extend]
无废话ExtJs 入门教程二十一[继承:Extend] extjs技术交流,欢迎加群(201926085) 在开发中,我们在使用视图组件时,经常要设置宽度,高度,标题等属性.而这些属性可以通过“继承” ...
- Bootstrap <基础二十一>徽章(Badges)
Bootstrap 徽章(Badges).徽章与标签相似,主要的区别在于徽章的边角更加圆滑. 徽章(Badges)主要用于突出显示新的或未读的项.如需使用徽章,只需要把 <span class= ...
- 【圣诞特献】Web 前端开发精华文章推荐【系列二十一】
<Web 前端开发精华文章推荐>2013年第九期(总第二十一期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和 ...
- Citrix 服务器虚拟化之二十一 桌面虚拟化之部署Provisioning Services
Citrix 服务器虚拟化之二十一 桌面虚拟化之部署Provisioning Services Provisioning Services 是Citrix 出品的一系列虚拟化产品中最核心的一个组件, ...
- 二十一、contextMap中放的常用数据
二十一.contextMap中放的常用数据 request:请求范围的数据.即ServletRequest中的那个Map parameters:请求参数的数据.即request.getParamete ...
- 牢记!SQL Server数据库开发的二十一条注意点
如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS). ...
- 转:二十一、详细解析Java中抽象类和接口的区别
转:二十一.详细解析Java中抽象类和接口的区别 http://blog.csdn.net/liujun13579/article/details/7737670 在Java语言中, abstract ...
- COJ 0979 WZJ的数据结构(负二十一)
WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...
- WCF技术剖析之二十一:WCF基本异常处理模式[下篇]
原文:WCF技术剖析之二十一:WCF基本异常处理模式[下篇] 从FaultContractAttribute的定义我们可以看出,该特性可以在同一个目标对象上面多次应用(AllowMultiple = ...
随机推荐
- Unable to resolve target 'android-19'
修改两个地方,解决上面的问题
- 图像处理工具包ImagXpress中如何定义查看器的属性
想要在图像处理控件ImagXpress中查看一个图像,首先需要创建一个查看器,之后你可以按照你自身的需要,来定义查看器的属性. 创建查看器 想要动态的创建一个查看器,需要先定义一个新的mageXVie ...
- struts2 笔记02 文件上传、文件下载、类型转换器、国际化的支持
Struts2的上传 1. Struts2默认采用了apache commons-fileupload 2. Struts2支持三种类型的上传组件 3. 需要引入commons-fileupload ...
- linux终端使用技巧
Shift+Ctrl+T:新建标签页Shift+Ctrl+W:关闭标签页Ctrl+PageUp:前一标签页Ctrl+PageDown:后一标签页Shift+Ctrl+PageUp:标签页左移Shift ...
- React Native 开发笔记
ReactNativeDemo 学习ReactNative开发,搭建ReactNative第一个项目 React Native 开发笔记 1.安装Homebrew $ /usr/bin/ruby -e ...
- ios tabbar 文字位置
[nav.tabBarItem setTitlePositionAdjustment)];
- HDU 5794:A Simple Chess(Lucas + DP)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5794 题意:让一个棋子从(1,1)走到(n,m),要求像马一样走日字型并只能往右下角走.里 ...
- Mysql ibdata 丢失或损坏如何通过frm&ibd 恢复数据
mysql存储在磁盘中,各种天灾人祸都会导致数据丢失.大公司的时候我们常常需要做好数据冷热备,对于小公司来说要做好所有数据备份需要支出大量的成本,很多公司也是不现实的.万一还没有做好备份,数据被误删除 ...
- CentOS安装、卸载jdk
安装:http://www.mamicode.com/info-detail-613410.html 卸载:http://sunqiusong.email.blog.163.com/blog/stat ...
- Redis 安装 启动 连接 配置 重启
Linux下安装 ]# wget http://download.redis.io/releases/redis-2.8.17.tar.gz ]# .tar.gz ]# cd redis- ]# ma ...