博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 590 二十一 Always on the run
阅读量:6509 次
发布时间:2019-06-24

本文共 5952 字,大约阅读时间需要 19 分钟。

 Always on the run
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit     
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.

 

 

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 
$1, 2, \dots, n$, where 1 is Paris, her starting point, and 
n is Atlanta, her final destination. The numbers will satisfy 
$2 \leŸ n \leŸ 10$ and 
$1 \leŸ k \leŸ 1000$.

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 ( $2, 3, \dots, n$), the next n - 1 lines to those from city 2 to all others ( $1, 3, 4, \dots, n$), and so on.

The description of the flight schedule itself starts with an integer d, the length of the period in days, with $1 \leŸ d \leŸ 30$. Following this ared non-negative integers, representing the cost of the flight between the two cities on days $1, 2, \dots, d$. 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.

 

 

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.

 

 

3 62 130 1503 75 0 807 120 110 0 100 110 120 04 60 70 60 503 0 135 1402 70 802 32 0 701 800 0

 

 

Scenario #1The best flight costs 460.Scenario #2No flight possible.

 

 


Miguel A. Revilla
1998-03-10
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 int dp[1005][12]; 7 int fly[12][12][35]; 8 int main() 9 {10 int n,k,ca=1;11 int i,j,l;12 while(scanf("%d %d",&n,&k)!=EOF)13 {14 if(n==0 && k==0)15 break;16 memset(fly,0,sizeof(fly));17 for(i=1;i<=n;i++)18 {19 for(j=1;j<=n;j++)20 {21 if(j==i)22 continue;23 scanf("%d",&fly[i][j][0]);24 for(l=1;l<=fly[i][j][0];l++)25 {26 scanf("%d",&fly[i][j][l]);27 }28 }29 }30 31 /*for(i=1;i<=n;i++)32 {33 for(j=1;j<=n;j++)34 {35 printf("%d:",fly[i][j][0]);36 for(l=1;l<=k;l++)37 printf("%d ",fly[i][j][l]);38 printf("\n");39 }40 printf("\n");41 }*/42 43 memset(dp,-1,sizeof(dp));44 dp[0][1]=0;45 for(l=1;l<=k;l++)46 {47 for(i=1;i<=n;i++)48 {49 if(dp[l-1][i]!=-1)50 {51 for(j=1;j<=n;j++)52 {53 if(fly[i][j][0]==0)54 continue;55 int ll;56 if(l%(fly[i][j][0])==0)57 ll=fly[i][j][0];58 else59 ll=l%fly[i][j][0];60 if(fly[i][j][ll]!=0)61 {62 if(dp[l][j]==-1)63 dp[l][j]=dp[l-1][i]+fly[i][j][ll];64 else65 dp[l][j]=min(dp[l][j],dp[l-1][i]+fly[i][j][ll]);66 }67 }68 }69 }70 }71 72 if(dp[k][n]!=-1)73 printf("Scenario #%d\nThe best flight costs %d.\n\n",ca++,dp[k][n]);74 else75 printf("Scenario #%d\nNo flight possible.\n\n",ca++);76 }77 return 0;78 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4771623.html

你可能感兴趣的文章
09值类型、引用类型、字符串
查看>>
Power BI连接至Mogo Altas Connector For BI
查看>>
Ubuntu 如何安装Google Chrome浏览器
查看>>
解决kindeditor编辑器中使用百度地图时不能拖动坐标的问题
查看>>
yaml 配置文件
查看>>
Uva 1626,括号序列
查看>>
深度优先算法
查看>>
LeetCode – Refresh – Majority Element
查看>>
Logger Rate Limiter
查看>>
centos6.5环境下svn服务器和客户端配置实用详解
查看>>
IE11下,用forms身份验证有问题了,好像是保存不了cookie
查看>>
the JAR file spring-beans-4.0.0.RELEASE.jar has no source attachment
查看>>
ethereumjs/merkle-patricia-tree-2-API
查看>>
go标准库的学习-runtime
查看>>
pytorch Debug —交互式调试工具Pdb (ipdb是增强版的pdb)-1-使用说明
查看>>
NodeJS学习之文件操作
查看>>
导入excel
查看>>
AJAX的get和post请求原生编写方法
查看>>
WebSocket 是什么原理?为什么可以实现持久连接
查看>>
Python自学笔记-logging模块详解
查看>>