当前位置:网站首页>Jumping | Blue Bridge Cup
Jumping | Blue Bridge Cup
2022-07-02 08:19:00 【Lewis_ one thousand two hundred and thirty-one】
jumping | Blue Bridge Cup
Topic link https://www.lanqiao.cn/problems/553/learning/



Topic analysis
The data structure of this problem is not big , May adopt dfs;
It's fine too dp;
The distance you can walk is only 9 individual , It is not allowed to walk two spaces below the syncline ( Although the distance is less than three ), There seems to be some problems here
Code
dfs
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int squ[101][101];
int book[101][101];
int dir[9][2] = {
1,0,2,0,3,0,0,1,0,2,0,3,1,1,1,2,2,1 };
int m, n;
int maxx = -1;
void dfs(int x, int y,int sum)
{
if (x == n && y == m)
{
if (sum > maxx)maxx = sum;
return;
}
for (int k = 0; k < 9; k++)
{
int nx = x + dir[k][0];
int ny = y + dir[k][1];
if (nx >= 1 && ny >= 1 && nx <= n && ny <= m&&!book[nx][ny])
{
book[nx][ny] = 1;
dfs(nx, ny, sum + squ[nx][ny]);
book[nx][ny] = 0;
}
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> squ[i][j];
book[1][1] = 1;
dfs(1, 1, -4);
cout << maxx;
return 0;
}
dp
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int squ[101][101];
int dp[101][101];
int dir[9][2] = {
1,0,2,0,3,0,0,1,0,2,0,3,1,1,1,2,2,1 };
int main()
{
int m, n;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> squ[i][j];
dp[1][1] = squ[1][1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
for (int k = 0; k < 9; k++)
{
int nx = i + dir[k][0];
int ny = j + dir[k][1];
if (nx >= 1 && ny >= 1 && nx <= n && ny <= m)
dp[nx][ny] = max(dp[nx][ny], dp[i][j] + squ[nx][ny]);
}
cout << dp[n][m];
return 0;
}
边栏推荐
- Summary of one question per day: String article (continuously updated)
- Carla-ue4editor import Roadrunner map file (nanny level tutorial)
- In the era of short video, how to ensure that works are more popular?
- Carsim-问题Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
- Force buckle method summary: sliding window
- STM32疑难杂症之ST-LINK Connection error INVALID ROM TABLE
- Opencv3 6.3 reduced pixel sampling with filters
- Carsim-路面3D形状文件参数介绍
- Sparse matrix storage
- cve_ 2019_ 0708_ bluekeep_ Rce vulnerability recurrence
猜你喜欢

Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?

【无标题】

cve_ 2019_ 0708_ bluekeep_ Rce vulnerability recurrence

Installation and use of simple packaging tools

使用Matplotlib绘制图表初步

Carsim-路面3D形状文件参数介绍

Carla-ue4editor import Roadrunner map file (nanny level tutorial)

w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决

How to build the alliance chain? How much is the development of the alliance chain

Chinese garbled code under vscade
随机推荐
Use of OpenCV 6.4 median filter
Wang extracurricular words
Static library and dynamic library
常量指针和指针常量
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
A brief analysis of graph pooling
St-link connection error invalid ROM table of STM32 difficult and miscellaneous diseases
Real world anti sample attack against semantic segmentation
Longest isometric subsequence
Comparison between setTimeout and requestanimationframe (page refresh)
Carsim-路面3D形状文件参数介绍
Causes of laptop jam
Library function of C language
包图画法注意规范
JVM instructions
Go functions make, slice, append
Specification for package drawing
Valin cable: BI application promotes enterprise digital transformation
The source code of the live app. When the verification method is mailbox verification, the verification code is automatically sent to the entered mailbox
16: 00 interview, came out at 16:08, the question is really too