Usaco Canada Tour

Source: Internet
Author: User

This problem means there are some points on the plane, these points from west to East distribution, now choose a route from the west to the east in turn, asked to choose a route to go as many cities as possible, we can regard this issue as two people from the west to the east, the definition of f[i][j] 1 toward I and 2 to J of the largest city number , f[j][i] = f[i][j] = max (f[i][k]) + 1, 1<=k<j, the result is Max (F[i][n]), the code is as follows:

/*id:m1500293 lang:c++ Prog:tour*/#include<cstdio>#include<algorithm>#include<cstring>#include<map>#include<string>#include<iostream>using namespacestd;intN, V;//number of vertices and number of routesintd[ the][ the];intf[ the][ the];intMain () {Freopen ("tour.in","R", stdin); Freopen ("Tour.out","W", stdout); CIN>>N>>V; Map<string,int>Rep; intnum =1;  for(intI=0; i<n; i++)    {        stringstr; CIN>>str; if(Rep.find (str) = =rep.end ()) Rep[str]= num++; }     for(intI=0; i<v; i++)    {        stringu, v; CIN>>u>>v; D[REP[U]][REP[V]]=1; D[rep[v]][rep[u]]=1; } f[1][1] =1;  for(intI=1; i<=n; i++)         for(intj=i+1; j<=n; J + +) {F[i][j]= -0x3fffffff;  for(intk=1; k<j; k++)//F[i][k]-> F[i][j]                if(D[k][j] && f[i][k]>0&& f[i][k]>F[i][j]) f[i][j]=F[i][k]; F[j][i]= ++F[i][j]; }    intAns =1;  for(intI=1; i<n; i++)//F[i][n] D[i][n]        if(D[i][n] && f[i][n]>ans) ans=F[i][n]; printf ("%d\n", ans); return 0;}

Usaco Canada Tour

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.