Always on the run

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Appoint description: 
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 kn 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的更多相关文章

  1. 无废话ExtJs 入门教程二十一[继承:Extend]

    无废话ExtJs 入门教程二十一[继承:Extend] extjs技术交流,欢迎加群(201926085) 在开发中,我们在使用视图组件时,经常要设置宽度,高度,标题等属性.而这些属性可以通过“继承” ...

  2. Bootstrap <基础二十一>徽章(Badges)

    Bootstrap 徽章(Badges).徽章与标签相似,主要的区别在于徽章的边角更加圆滑. 徽章(Badges)主要用于突出显示新的或未读的项.如需使用徽章,只需要把 <span class= ...

  3. 【圣诞特献】Web 前端开发精华文章推荐【系列二十一】

    <Web 前端开发精华文章推荐>2013年第九期(总第二十一期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和  ...

  4. Citrix 服务器虚拟化之二十一 桌面虚拟化之部署Provisioning Services

    Citrix 服务器虚拟化之二十一  桌面虚拟化之部署Provisioning Services Provisioning Services 是Citrix 出品的一系列虚拟化产品中最核心的一个组件, ...

  5. 二十一、contextMap中放的常用数据

    二十一.contextMap中放的常用数据 request:请求范围的数据.即ServletRequest中的那个Map parameters:请求参数的数据.即request.getParamete ...

  6. 牢记!SQL Server数据库开发的二十一条注意点

    如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL  Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS). ...

  7. 转:二十一、详细解析Java中抽象类和接口的区别

    转:二十一.详细解析Java中抽象类和接口的区别 http://blog.csdn.net/liujun13579/article/details/7737670 在Java语言中, abstract ...

  8. COJ 0979 WZJ的数据结构(负二十一)

    WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...

  9. WCF技术剖析之二十一:WCF基本异常处理模式[下篇]

    原文:WCF技术剖析之二十一:WCF基本异常处理模式[下篇] 从FaultContractAttribute的定义我们可以看出,该特性可以在同一个目标对象上面多次应用(AllowMultiple = ...

随机推荐

  1. 一个noconsole程序

    貌似是一个外国人写的,作用应该是让控制台的程序运行的时候不会弹出那个控制台黑框.想用来让它不显示 php-cgi.exe 运行后的窗口,可是效果不是预期的. 项目在 github 的位置:https: ...

  2. 「Ruby && Sqlite3」How to install sqlite3 for ruby? (solve: sqlite-ruby no such file...)

    error message:           no such file .... 安装 gem install sqlite3-ruby -- --with-sqlite3-dir=/usr/lo ...

  3. sql语句中where和having的区别

    WHERE语句在GROUPBY语句之前:SQL会在分组之前计算WHERE语句. HAVING语句在GROUPBY语句之后:SQL会在分组之后计算HAVING语句.

  4. C++笔试题(部分)

    1.简述C++11和Boost 2.struct和union与class的区别 3.为什么C++中调用被C编译器编译后的函数要加extern C声明? 4.以下代码哪里不对? #pragma regi ...

  5. StringTokenizer类

    StringTokenizer是一个用来分隔String字符串的应用类. 1.构造函数 public StringTokenizer(String str)  //构造一个用来解析str的String ...

  6. 1行代码,删除svn文件夹

    引用:http://www.cnblogs.com/Alexander-Lee/archive/2010/02/23/1671905.html linux操作系统: find -name .svn | ...

  7. android 项目学习随笔十三(ListView实现ITEM点击事件,将已读状态持久化到本地)

    1.因为给LISTVIEW增加了两个头布局,所以在点击事件ITEM索引会增加2,比如原来第一条数据的索引应该为0,增加两个头布局后,它的索引变为        2,为了使LISTVIEW的ITEM在点 ...

  8. Android NDK 开发(一)--环境搭建【转】

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/41800955 Android下的NDK开发是Android开发中不可或缺的一部分, ...

  9. TM1680的I2C的51例程

    搞到一个例程,虽然是51的, 但是我的ST版本也是用的模拟I2C, 分析一下吧: unsigned char i=0;TM1680start();  //I2C起始信号 TM1680SendByte( ...

  10. datatables条件判断列显示还是隐藏

    定义一个状态变量status根据条件取值true或者false,然后在datatables参数设置中相应的columns属性的data后面加上"visible":status,该列 ...