USACO Seciton 5.4 Canada Tour(dp)
因为dp(i,j)=dp(j,i),所以令i>j. dp(i,j)=max(dp(k,j))+1(0<=k<i),若此时dp(i,j)=1则让dp(i,j)=0.(因为无法到达此状态,等于1是因为后来加1了).初始:dp(0,0)=1.answer: max(dp(i,n-1))(0<=i<n).比较难理解的是为什么状态转移时为什么不会出现重复,只要我们每次计算时没有计算重复点,那么之前的计算也不会有(因为是同样的dp计算方式),所以就不会重复.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Canada Tour
You have won a contest sponsored by an airline. The prize is a ticket to travel around Canada, beginning in the most western point served by this airline, then traveling only from west to east until you reach the most eastern point served, and then coming back only from east to west until you reach the starting city. No city may be visited more than once, except for the starting city, which must be visited exactly twice (at the beginning and the end of the trip). You are not allowed to use any other airline or any other means of transportation.
Given a list of cities served by the airline and a list of direct flights between pairs of cities, find an itinerary which visits as many cities as possible and satisfies the above conditions beginning with the first city and visiting the last city on the list and returning to the first city.
PROGRAM NAME: tour
INPUT FORMAT
Line 1: | The number N of cities served by the airline and the number V of direct flights that will be listed. N will be a positive integer not larger than 100. V is any positive integer. |
Lines 2..N+1: | Each line contains a name of a city served by the airline. The names are ordered from west to east in the input file. There are no two cities in the same meridian. The name of each city is a string of, at most, 15 digits and/or characters of the Latin alphabet; there are no spaces in the name of a city. |
Lines N+2..N+2+V-1: | Each line contains two names of cities (taken from the supplied list), separated by a single blank space. This pair is connected by a direct, two-way airline flight. |
SAMPLE INPUT (file tour.in)
8 9 Vancouver Yellowknife Edmonton Calgary Winnipeg Toronto Montreal Halifax Vancouver Edmonton Vancouver Calgary Calgary Winnipeg Winnipeg Toronto Toronto Halifax Montreal Halifax Edmonton Montreal Edmonton Yellowknife Edmonton Calgary
OUTPUT FORMAT
Line 1: | The number M of different cities visited in the optimal itinerary. Output 1 if no itinerary is possible. |
SAMPLE OUTPUT (file tour.out)
7
Namely: Vancouver, Edmonton, Montreal, Halifax, Toronto, Winnipeg, Calgary, and Vancouver (but that's not a different city).
USACO Seciton 5.4 Canada Tour(dp)的更多相关文章
- USACO 5.4 Canada Tour
Canada Tour You have won a contest sponsored by an airline. The prize is a ticket to travel around C ...
- [洛谷P2747] [USACO5.4]周游加拿大Canada Tour
洛谷题目链接:[USACO5.4]周游加拿大Canada Tour 题目描述 你赢得了一场航空公司举办的比赛,奖品是一张加拿大环游机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行, ...
- 洛谷 P2747 [USACO5.4]周游加拿大Canada Tour 解题报告
P2747 [USACO5.4]周游加拿大Canada Tour 题目描述 你赢得了一场航空公司举办的比赛,奖品是一张加拿大环游机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行,直 ...
- 洛谷 P2747 [USACO5.4]周游加拿大Canada Tour
P2747 [USACO5.4]周游加拿大Canada Tour 题目描述 你赢得了一场航空公司举办的比赛,奖品是一张加拿大环游机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行,直 ...
- USACO 6.5 Betsy's Tour (插头dp)
Betsy's TourDon Piele A square township has been divided up into N2 square plots (1 <= N <= 7) ...
- 洛谷P2747周游加拿大Canada Tour [USACO5.4] dp
正解:dp 解题报告: 传送门! 其实这题是我做网络流的时候发现了这题,感觉有点像双倍经验,,,? 但是我还不想写网络流的题解,,,因为网络流24题都还麻油做完,,,想着全做完了再写个总的题解什么的( ...
- POJ2677 Tour[DP 状态规定]
Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4307 Accepted: 1894 Description ...
- 【USACO 2.2】Subset Sums (DP)
N (1 <= N <= 39),问有多少种把1到N划分为两个集合的方法使得两个集合的和相等. 如果总和为奇数,那么就是0种划分方案.否则用dp做. dp[i][j]表示前 i 个数划分到 ...
- POJ2677 Tour(DP+双调欧几里得旅行商问题)
Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3929 Accepted: 1761 Description ...
随机推荐
- VPN的分类方式
VPN的分类方式 VPN的分类方式比较混乱.不同的生产厂家在销售它们的VPN产品时使用了不同的分类方式,它们主要是产品的角度来划分的.不同的ISP在开展VPN业务时也推出了不同的分类方式,他们主 ...
- CentOS 七 vs CentOS 6的不同
CentOS 七 vs CentOS 6的不同 CentOS 7 vs CentOS 6的不同(1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME ...
- Sublime Text 3:3114的安装(目前最新),插件emmet的安装
随便一些好了. 直接英文版吧,建议不要找中文版,学习英语不是? https://www.sublimetext.com/3 下载 https://github.com/wbond/package_ ...
- matlab GUI之自定义菜单小结
自定义菜单 1.uimenu对象 h=uimenu('PropertyName','ProperValue') h=uimenu(parent,'PropertyName','ProperValue' ...
- 2014.8.16 if语句
语句 if语句 大体可以分一下几种: 小知识 生成一个随机数: Random sss = new Random(); int a = sss.Next(100); Console.WriteLine ...
- Building Workspace速度慢的原因
今天把ext3.0部署到web project很慢很慢,查了一下,这个当笔记. 转自http://blog.163.com/jong_cai/blog/static/87028045201311178 ...
- Mvc--Html.ActionLink()用法
},new{ target="_blank"})会生成 <a href="Products/Detail/1" target="_blank&q ...
- java web简易网上书店项目系列,使用MVC模式(servlet+jstl+dbutils),开篇
一. 针对很多java web初学者入门困难的问题,笔者利用一个小型web项目,一步一步的展示java web开发方法,每一个章节引入一些java web开发的重点知识,让同学们可以将java web ...
- TCP的流量控制
TCP协议作为一个可靠的面向字节流的传输协议,其可靠性和流量控制由滑动窗口协议保证,而拥塞控制则由控制窗口结合一系列的控制算法实现. 要区分TCP的流量控制和拥塞控制: 流量控制是发送方的发送数据的速 ...
- [C#参考]UI和线程(一)
Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程. 什么是进程呢?当一个程序开始运行时,它就是一个进程,进程所指包 ...