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 = ...
随机推荐
- 夺命雷公狗---node.js---15之加密
node其实也给我们留下了密码的加密发送,不过一般都是用cmd5加密其实也是够了,但是sha1加密也要提下: /** * Created by leigood on 2016/8/31. */ var ...
- C#语言基础2016/3/6
一. 基础知识 输入输出 Console.Write();//输出语句,自动换行 Console.WriteLine();//输出语句 Console.WriteLine();输入语句 Consol ...
- PHP自动生成后台导航网址的最佳方法
'http://www.jbxue.com'=> '脚本学堂首页', </script>
- 【海岛帝国系列赛】No.7 海岛帝国:神圣之日
50237242海岛帝国:神圣之日 [试题描述] 战争持续九个月了.“购物券”WHT的军队还在跟恐怖分子僵持着.WHT和LJX已经向“公务员”告急,情况不宜乐观.YSF为守护帝国决定打开“够累 的”星 ...
- ADB server didn't ACK的解决方法
异常信息如下: C:\Users\Administrator>adb devices* daemon not running. starting it now on port 5037 *ADB ...
- Loadrunner教程读后感-VuGen
一.loadrunner协议分析 协议确定方法 二.提交表单函数的区别 (1)web_sumit_form() (2)web_sumit_data() 三.web_url和web_link 四.VuG ...
- linux 文件删除原理
文件删除: i_link 文件的硬连接数 i_count 引用计数(有一个程序使用i_count加1) 文件删除的条件: i_link=0 and i_count=0 被进程占用的文件可以删除
- 连接ssh反应很慢,卡,延迟
1.关闭DNS反向解析在linux中,默认就是开启了SSH的反向DNS解析,这个会消耗大量时间,因此需要关闭.# vi /etc/ssh/sshd_configUseDNS=no 在配置文件中,虽然U ...
- 获取一个字符串中每一个字母出现的次数使用map集合
package 获取字符串中单字符出现次数; import java.util.Scanner; import java.util.TreeMap; /* * 需求:获取一个字符串中每一个字母出现的次 ...
- [转]How Can I Find Out What Is Using a Busy or Reserved Serial Port?
转自:http://digital.ni.com/public.nsf/allkb/29B079481C5ECE76862578810082394E How Can I Find Out What I ...