当前位置:网站首页>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;
}
边栏推荐
- 最长等比子序列
- Opencv's experience of confusing X and Y coordinates
- E-R draw clear content
- How to uninstall SQL Server cleanly
- STM32-新建工程(参考正点原子)
- Global and Chinese market of snow sweepers 2022-2028: Research Report on technology, participants, trends, market size and share
- OpenCV常用方法出处链接(持续更新)
- Dynamic extensible representation for category incremental learning -- der
- Matlab other
- 高中数学必修一
猜你喜欢
![[dynamic planning] p4170: coloring (interval DP)](/img/52/76f8baebb19fe10db91c74fec9a697.jpg)
[dynamic planning] p4170: coloring (interval DP)

Valin cable: BI application promotes enterprise digital transformation

Simply test the two different data transmission methods of content length and chunked

Use C language to receive JSON strings

Sequence problem for tqdm and print

St-link connection error invalid ROM table of STM32 difficult and miscellaneous diseases

Installation and use of simple packaging tools

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

2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers

Specification for package drawing
随机推荐
Live broadcast platform development, flexible menu, and freely adjust the horizontal size of the menu bar
Global and Chinese market of tillage finishing machines 2022-2028: Research Report on technology, participants, trends, market size and share
用C# 语言实现MYSQL 真分页
SQL server如何卸载干净
Carsim-实时仿真的动画同步问题
Animation synchronization of CarSim real-time simulation
STM32-新建工程(参考正点原子)
STL速查手册
Wang extracurricular words
简易打包工具的安装与使用
力扣每日一题刷题总结:栈与队列篇(持续更新)
W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it
Sqlyog remote connection to MySQL database under centos7 system
常量指针和指针常量
How to build the alliance chain? How much is the development of the alliance chain
When a custom exception encounters reflection
The internal network of the server can be accessed, but the external network cannot be accessed
Development of digital collection trading website development of metauniverse digital collection
Learn to write article format
应对长尾分布的目标检测 -- Balanced Group Softmax