Dynamic Planning--board

Source: Internet
Author: User

Wikioi 1010 River crossing StrokeTitle Description Description

, a point has a river stroke, need to go to target point B. Stroke rule: can be down, or to the right. At the same time on the board at any point there is a horse (such as the C point), the point where the horse is located and all jumps one step up to the point known as the other horse's control points. For example, a horse on a C point can control 9 points (the p1,p2 in the picture ...). P8 and C). The stroke cannot pass through the other horse's control point.


The chessboard coordinates, A point (0,0), B Point (N,m) (N,m is not more than 20 integer, and by the keyboard input), the same position coordinates of the horse is required (convention: C is not equal to a, and C is not equal to B). You are now asked to calculate the number of strokes from the point where a is able to reach point B.

1<=n,m<=15

Enter a description Input Description

Keyboard input
Coordinates of Point B (n,m) and coordinates of the opponent's horse (x, y) {no error}

Output description Output Description

Screen output
An integer (the number of bars in the path).

Sample input Sample Input

6 6 3 2

Sample output Sample Output

17

Data range and Tips Data Size & Hint

As described

Ideas:

DP, preprocess all reachable points first

Code:

1#include <iostream>2#include <cstdio>3#include <string>4#include <cstring>5#include <algorithm>6 7 using namespacestd;8 Const intMAXN = $;9 intN,M,X,Y,DP[MAXN][MAXN],VIS[MAXN][MAXN];Ten  One intMain () { ACin>>n>>m>>x>>y; -memset (Vis,0,sizeof(Vis)); -Memset (DP,0,sizeof(DP)); then++; -m++; -X + +; -y++; +Vis[x][y] = vis[x-1][y+2] = vis[x-2][y+1] = vis[x-2][y-1] = vis[x-1][y-2] = vis[x+1][y+2] = vis[x+2][y+1] = vis[x+2][y-1] = vis[x+1][y-2] = -1; -dp[1][1] =1; +      for(inti =1; I <= n;i++){ A          for(intj =1; J <= m;j++){ at             if(Vis[i][j]! =-1){ -DP[I][J] = max (dp[i][j],dp[i-1][J] + dp[i][j-1]); -             } -              -         } -     } incout<<Dp[n][m]; -     return 0; to}
View Code

Dynamic Planning--board

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.