当前位置:网站首页>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;
}
边栏推荐
- Constant pointer and pointer constant
- Installation and use of simple packaging tools
- 力扣每日一题刷题总结:栈与队列篇(持续更新)
- Chinese garbled code under vscade
- Introduction to anti interception technology of wechat domain name
- 笔记本电脑卡顿问题原因
- Sparse matrix storage
- Data reverse attack under federated learning -- gradinversion
- 静态库和动态库
- 力扣方法总结:双指针
猜你喜欢

MySQL optimization

Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)

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

C language implements XML generation and parsing library (XML extension)

Carsim 学习心得-粗略翻译1

Array and string processing, common status codes, differences between PHP and JS (JS)

Several methods of image enhancement and matlab code

简易打包工具的安装与使用

使用wireshark抓取Tcp三次握手

2022 Heilongjiang's latest eight member (Safety Officer) simulated test question bank and answers
随机推荐
Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
力扣方法总结:滑动窗口
Common shortcut keys of Jupiter notebook (you can also view it by pressing h in command mode)
Get the width and height of the screen in real time (adaptive)
Income in the first month of naked resignation
力扣每日一题刷题总结:链表篇(持续更新)
Erase method in string
Force buckle method summary: sliding window
Real world anti sample attack against semantic segmentation
Global and Chinese market of recovery equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
程序猿学英语-指令式编程
W10 is upgraded to W11 system, but the screen is black, but the mouse and desktop shortcuts can be used. How to solve it
One of the reasons for WCF update service reference error
Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)
Fundamentals of music theory (brief introduction)
使用wireshark抓取Tcp三次握手
关于原型图的深入理解
Use of OpenCV 6.4 median filter
力扣方法总结:双指针