bzoj4745: [Usaco2016 dec]cow Checklist Time limit:10 Sec Memory limit:128 MB
Submit:1 solved:1
[Submit] [Status] [Discuss] Descriptionevery Day, Farmer John walks through he pasture to check in the well-being of each of your his cows. Onhis Farm He has breeds of cows, Holsteins and guernseys. His HH Holsteins is conveniently numbered 1 ... H, and his GG guernseys is conveniently numbered 1 ... G (1≤h≤1000,1≤g≤1000). Each Cowis located at a point in the 2D plane (not necessarily distinct). Farmer John starts his tour at Holstein 1, and ends at Holstein HH. He wants to visit each cow along the by, and for convenience in maintaining he checklist of cows visited so far, he want s to visit the Holsteins and guernseys in Theorder in which they is numbered. In the sequence of all h+gh+g cows he visits, the Holsteins numbered 1 ... H should appear as a (not necessarily contiguous) subsequence, and likewise for the guernseys. Otherwise stated, the sequence of all h+gh+g cows should is formed by interleaving the list of holsteins numbered 1...H With the list of guernseys numbered 1 ... Gwhen FJ moves from one cow to AnotShe cow traveling a distance of D, he expends D2 energy. Him determine the minimum amount ofenergy required to visit all he cows according to a tour as described Abov e.
Inputthe first line of input contains H and G, separated by a space. The next H lines contain the xx and yy coordinates of the HH Holsteins, and the next G lines after that contain coordinate S of the guernseys. Each coordinate are an integer in the range 0 ... 1000
Outputwrite a single line of output, giving the minimum energy required for FJ's tour of all the cows.
Sample Input3 2
0 0
1 0
2 0
0 3
1 3Sample Output -HINT Source
F[I][J][0/1] represents the first array to match to I second to J currently at the minimum cost of the number of transfers see Code
1#include <bits/stdc++.h>2 #defineRep (i,l,r) for (int i=l;i<=r;++i)3 using namespacestd;4 Const intn= -;5 structzs{6 intx, y;7 }s[n];8typedefLong Longll;9 intN,m,mp[n][n];Tenll f[n][n][2]; One intMain () { Ascanf"%d%d",&n,&m); -Rep (I,1, N) scanf ("%d%d",&s[i].x,&s[i].y); -Rep (I,1, m) scanf ("%d%d", &s[i+n].x,&s[i+n].y); theRep (I,1, N+m) Rep (J,1, n+m) mp[i][j]= (s[i].x-s[j].x) * (s[i].x-s[j].x) + (S[I].Y-S[J].Y) * (s[i].y-s[j].y); -Rep (I,0, N) Rep (J,0, m) Rep (K,0,1) f[i][j][k]=1ll<< -; -f[1][0][0]=0; -Rep (I,1, N) Rep (J,0, M) { +f[i][j][0]=min (f[i][j][0],min (f[i-1][j][0]+mp[i-1][i],f[i-1][j][1]+mp[n+J] [i])); - if(j) f[i][j][1]=min (f[i][j][1],min (f[i][j-1][0]+mp[i][n+j],f[i][j-1][1]+mp[n+j-1][n+j])); + } Aprintf"%lld\n", f[n][m][0]); at}
View Code
bzoj4745: [Usaco2016 dec]cow checklist