


Codeforces Round #224 (Div. 2) D Brute force search plus memoization_html/css_WEB-ITnose
I have been reading the question for half a year, and my English is terrible. The meaning of the question is to place two chess pieces on the chessboard as the starting point, but the starting point cannot be on #, and then start moving according to the instructions in the picture, < left> right ^Up v Down, when moving, you can only follow the instructions in the picture. If there is a # in front of you, you can walk in, but you can't walk anymore. The two chess pieces can't touch each other while walking, but they will both move in the end. It's okay to go to the same #, and if you can take infinite steps, output -1, for example > < In this way, you can move left and right infinitely, and then ask you the sum of the maximum number of steps taken by the two chess pieces
I was trapped by the output of -1 at first, because in addition to... When writing dfs, the image is 2000 * 2000, which is a bit big. I didn’t expect reverse DFS. I have no choice but to perform a memory search. Let dis[i][j] represent the steps that can be taken from (i, j) as the starting point. The furthest number of steps, so that the time should be able to pass, and then enumerate each point as the starting point for in-depth search, here you can judge whether it is -1, because the picture is 2000 * 2000, so you can go up to 4000000 The number of moves, if two chess pieces move in tandem, will not exceed 8000000 at most, so you can set a maximum value MAXN = 8000000. Once the marked point is moved again, this value will be returned, and the judgment can be made. Whether it is -1,
After finding the maximum number of steps for each point as the starting point, start searching. If there are two points with the same maximum number of steps, and they do not collide during the walking process, then The maximum sum of steps is ans ans . If you can't find it, placing two chess pieces one after another will definitely be the optimal one, which is ans ans - 1. Okay, here is the implementation of the code. The deep search is a bit confusing,
const int MAXN = 8000000 + 55;char aa[2000 + 55][2000 + 55];int mp[2000 + 55][2000 + 55];int xx[5] = {-1,1,0,0};int yy[5] = {0,0,-1,1};int dis[2000 + 55][2000 + 55];bool vis[2000 + 55][2000 + 55];int bb[2000 + 55][2000 + 55];int n,m;int ans;void init() { memset(aa,0,sizeof(aa)); memset(mp,0,sizeof(mp)); memset(dis,-1,sizeof(dis)); memset(vis,0,sizeof(vis)); memset(bb,-1,sizeof(bb));}bool input() { while(scanf("%d %d",&n,&m) == 2) { for(int i=0;i')mp[i][j] = 3; } } return false; } return true;}bool isok(int x,int y) { if(x <0 || x >=n || y < 0 || y >= m)return true; return false;}int dfs1(int x,int y) { if(isok(x,y))return 0; if(vis[x][y])return MAXN; if(dis[x][y] != -1) return dis[x][y]; vis[x][y] = 1; if(mp[x][y] == -1) { vis[x][y] = 0; dis[x][y] = 0; return 0; } else { int tmp = dfs1(x + xx[mp[x][y]],y + yy[mp[x][y]]) + 1; vis[x][y] = 0; dis[x][y] = tmp; return tmp; }}int dfs2(int x,int y,int cnt) { if(bb[x][y] != -1) { if(bb[x][y] == cnt && mp[x][y] != -1)return 0; return 1; } if(mp[x][y] == -1) { bb[x][y] = cnt; return 1; } else { bb[x][y] = cnt; return dfs2(x + xx[mp[x][y]],y + yy[mp[x][y]],cnt + 1); }}void cal() { ans = 0; int mark; for(int i=0;i = MAXN){ans = MAXN;return;} ans = max(ans,tmp); } } if(ans == 0)return ; mark = 0; for(int i=0;i 1){ans *= 2;return ;} } } } ans += (ans - 1);}void output() { if(ans >= MAXN)puts("-1"); else cout<

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When you click the search field in Windows 11, the search interface automatically expands. It displays a list of recent programs on the left and web content on the right. Microsoft displays news and trending content there. Today's check promotes Bing's new DALL-E3 image generation feature, the "Chat Dragons with Bing" offer, more information about dragons, top news from the Web section, game recommendations, and the Trending Search section. The entire list of items is independent of your activity on your computer. While some users may appreciate the ability to view news, all of this is abundantly available elsewhere. Others may directly or indirectly classify it as promotion or even advertising. Microsoft uses interfaces to promote its own content,

How does Xianyu search for users? In the software Xianyu, we can directly find the users we want to communicate with in the software. But I don’t know how to search for users. Just view it among the users after searching. Next is the introduction that the editor brings to users about how to search for users. If you are interested, come and take a look! How to search for users in Xianyu? Answer: View details among the searched users. Introduction: 1. Enter the software and click on the search box. 2. Enter the user name and click Search. 3. Select [User] under the search box to find the corresponding user.

How to use Baidu Advanced Search Baidu search engine is currently one of the most commonly used search engines in China. It provides a wealth of search functions, one of which is advanced search. Advanced search can help users search for the information they need more accurately and improve search efficiency. So, how to use Baidu advanced search? The first step is to open the Baidu search engine homepage. First, we need to open Baidu’s official website, which is www.baidu.com. This is the entrance to Baidu search. In the second step, click the Advanced Search button. On the right side of the Baidu search box, there is

In the era dominated by intelligence, office software has also become popular, and Wps forms are adopted by the majority of office workers due to their flexibility. At work, we are required not only to learn simple form making and text entry, but also to master more operational skills in order to complete the tasks in actual work. Reports with data and using forms are more convenient, clear and accurate. The lesson we bring to you today is: The WPS table cannot find the data you are searching for. Why please check the search option location? 1. First select the Excel table and double-click to open it. Then in this interface, select all cells. 2. Then in this interface, click the "Edit" option in "File" in the top toolbar. 3. Secondly, in this interface, click "

The following example prints files in a directory based on their extension - Example importjava.io.IOException;importjava.nio.file.Files;importjava.nio.file.Path;importjava.nio.file.Paths;importjava.util.stream.Stream; publicclassDemo{ publicstaticvoidmain(String[]args)throwsIOException{ 

The mobile Taobao app software provides a lot of good products. You can buy them anytime and anywhere, and everything is genuine. The price tag of each product is clear. There are no complicated operations at all, making you enjoy more convenient shopping. . You can search and purchase freely as you like. The product sections of different categories are all open. Add your personal delivery address and contact number to facilitate the courier company to contact you, and check the latest logistics trends in real time. Then some new users are using it for the first time. If you don’t know how to search for products, of course you only need to enter keywords in the search bar to find all the product results. You can’t stop shopping freely. Now the editor will provide detailed online methods for mobile Taobao users to search for store names. 1. First open the Taobao app on your mobile phone,

How to use PHP functions to search and filter data? In the process of developing using PHP, it is often necessary to search and filter data. PHP provides a wealth of functions and methods to help us achieve these operations. This article will introduce some commonly used PHP functions and techniques to help you search and filter data efficiently. String search Commonly used string search functions in PHP are strpos() and strstr(). strpos() is used to find the position of a certain substring in a string. If it exists, it returns

How to use the hash search algorithm in C++ The hash search algorithm is an efficient search and storage technology. It converts keywords into a fixed-length index through a hash function, and then uses this index in the data structure Search. In C++, we can implement hash search algorithms by using hash containers and hash functions from the standard library. This article will introduce how to use the hash search algorithm in C++ and provide specific code examples. Introducing header files and namespaces First, before using the hash search algorithm in C++
