当前位置:网站首页>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;
}
边栏推荐
- Longest isometric subsequence
- Static library and dynamic library
- Backup, recovery and repair of XFS file system
- Comparison between setTimeout and requestanimationframe (page refresh)
- Introduction to parameters of CarSim pavement 3D shape file
- Matlab-其它
- Chinese garbled code under vscade
- Rhel7 operation level introduction and switching operation
- Matlab - autres
- 16: 00 interview, came out at 16:08, the question is really too
猜你喜欢
Static library and dynamic library
Sequence problem for tqdm and print
Income in the first month of naked resignation
MySQL optimization
Carsim-问题Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
Using transformer for object detection and semantic segmentation
【无标题】
cve_ 2019_ 0708_ bluekeep_ Rce vulnerability recurrence
Principes fondamentaux de la théorie musicale (brève introduction)
Development of digital collection trading website development of metauniverse digital collection
随机推荐
11月24号,我们为“满月”庆祝
Global and Chinese markets of tilting feeders 2022-2028: Research Report on technology, participants, trends, market size and share
Brief introduction of prompt paradigm
力扣每日一题刷题总结:栈与队列篇(持续更新)
OpenCV关于x,y坐标容易混淆的心得
Find and rfind methods in string
The internal network of the server can be accessed, but the external network cannot be accessed
Carsim-问题Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
E-R draw clear content
简易打包工具的安装与使用
Using C language to realize MySQL true paging
Longest isometric subsequence
Installation and use of simple packaging tools
Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
St-link connection error invalid ROM table of STM32 difficult and miscellaneous diseases
In depth understanding of prototype drawings
MySQL optimization
Jz-061-serialized binary tree
Global and Chinese market of wire loop, 2022-2028: Research Report on technology, participants, trends, market size and share
Live broadcast platform development, flexible menu, and freely adjust the horizontal size of the menu bar