"Usaco Open Gold" 2.Crisis on the Farm dynamic Regulation,

Source: Internet
Author: User

Test instructions: input n, m, p then n Cow Tower coordinates, m-haystack coordinates, p-order opportunity.

Each instruction can move up or down One direction, allowing all Nouta to be moved one unit at a time.

Then every haystack/Ox tower, there are 1 weights.

The maximum value of the weighted value and the maximum weight of the moving instruction sequence (minimum dictionary order).


F[i][j][k] Represents the first I, moving sequence x axis coordinates of J,y axis K, the maximum weight.


Then do it backwards to make sure the dictionary is ordered.


Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 1010# Define M 32#define inf 0x3f3f3f3fusing namespace std;int n,m,p;int map[n][n];int cx[n],cy[n];int lx=inf,rx,ly=inf,ry;int F[m][m<<1][m<<1],ans;char Opt[m][m<<1][m<<1];int Main () {//freopen ("test.in", "R", stdin); int I,j,k;int a,b,c;int x,y;scanf ("%d%d%d", &n,&m,&p), for (i=1;i<=n;i++) scanf ("%d%d", &cx[i], &cy[i]); for (i=1;i<=m;i++) {scanf ("%d%d", &x,&y); Map[x][y]=1;lx=min (lx,x), Rx=max (rx,x); Ly=min (ly,y ), Ry=max (ry,y);} for (i=p;i>=0;i--)//Walk I step {for (j=-i;j<=i;j++)//x-axis offset {int remain=i-abs (j); for (k=-remain;k<=remain;k++) {int Noxus=-1,demacia=0;char tt;for (int adc=1;adc<=n;adc++) {x=cx[adc]+j,y=cy[adc]+k;if (Lx<=x&&x<=rx &&ly<=y&&y<=ry&&map[x][y]) demacia++;} if (F[i+1][j+1+m][k+m]>noxus) noxus=f[i+1][j+1+m][k+m],tt= ' E '; if (F[i+1][j+m][k+1+m]>noxus) Noxus=f[i+1][j+M ][k+1+m],tt= ' N '; if (f[I+1] [J+m] [K-1+m]>noxus) noxus=f[i+1][j+m][k-1+m],tt= ' S '; if (f[i+1][j-1+m][k+m]>noxus) noxus=f[i+1][j-1+m][k+m],tt= ' W '; f[i][j+m][k+m]=noxus+demacia;opt[i][j+m][k+m]=tt;}}} printf ("%d\n", F[0][0+m][0+m]), X=y=0+m;for (i=0;i<p;i++) {printf ("%c", Opt[i][x][y]), if (opt[i][x][y]== ' E ') x + +; else if (opt[i][x][y]== ' W ') x--;else if (opt[i][x][y]== ' N ') y++;else if (opt[i][x][y]== ' S ') y--;} return 0;}


Copy to Google TranslateTranslation Results

"Usaco Open Gold" 2.Crisis on the Farm dynamic Regulation,

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.