标签:des style blog http io ar color os sp
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.
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 are d 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.
If it is not possible to travel in such a way, print ``No flight possible.‘‘.
Print a blank line after each scenario.
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
Scenario #1 The best flight costs 460. Scenario #2 No flight possible.
题意:n座城市,k天,问最后到达第n个城市的最小花费。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> typedef long long LL; using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) const int INF=0x3f3f3f3f; int dp[1100][15]; int mp[35][15][15]; int num[15][15]; int n,k; int main() { int cas=1; std::ios::sync_with_stdio(false); while(~scanf("%d%d",&n,&k)&&(n+k)) { CLEAR(mp,0); CLEAR(dp,INF); dp[0][1]=0; REPF(i,1,n) { REPF(j,1,n) { if(i!=j) { scanf("%d",&num[i][j]); REP(kk,num[i][j])//从0开始方便循环 scanf("%d",&mp[kk][i][j]); } } } printf("Scenario #%d\n",cas++); REPF(kk,1,k) { REPF(i,1,n) { REPF(j,1,n) { if(i==j) continue; int cost=mp[(kk-1)%num[j][i]][j][i]; if(cost==0) continue; dp[kk][i]=min(dp[kk][i],dp[kk-1][j]+cost); } } } if(dp[k][n]<INF) printf("The best flight costs %d.\n",dp[k][n]); else printf("No flight possible.\n"); puts(""); } }
标签:des style blog http io ar color os sp
原文地址:http://blog.csdn.net/u013582254/article/details/41392841