当前位置:网站首页>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;
}
边栏推荐
- Organigramme des activités
- Use Matplotlib to draw a preliminary chart
- Vscode下中文乱码问题
- Chinese garbled code under vscade
- Matlab数学建模工具
- 笔记本电脑卡顿问题原因
- Longest isometric subsequence
- Global and Chinese market of wire loop, 2022-2028: Research Report on technology, participants, trends, market size and share
- What are the platforms for selling green label domain names? What is the green label domain name like?
- The internal network of the server can be accessed, but the external network cannot be accessed
猜你喜欢

Matlab数学建模工具

Introduction to parameters of CarSim pavement 3D shape file

Use of opencv3 6.2 low pass filter

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

Generate database documents with one click, which can be called swagger in the database industry

使用C#语言来进行json串的接收

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

Sqlyog remote connection to MySQL database under centos7 system

Several methods of image enhancement and matlab code

Using transformer for object detection and semantic segmentation
随机推荐
AR system summary harvest
静态库和动态库
程序猿学英语-Learning C
C language implements XML generation and parsing library (XML extension)
Introduction to parameters of CarSim pavement 3D shape file
Static library and dynamic library
高中数学必修一
How to wrap qstring strings
包图画法注意规范
Carsim 学习心得-粗略翻译1
Global and Chinese markets of tilting feeders 2022-2028: Research Report on technology, participants, trends, market size and share
Using C language to realize MySQL true paging
On the confrontation samples and their generation methods in deep learning
Introduction to anti interception technology of wechat domain name
Matlab other
Short video with goods source code, double-click to zoom in when watching the video
Carla-ue4editor import Roadrunner map file (nanny level tutorial)
Simply test the two different data transmission methods of content length and chunked
C语言的库函数
Simple implementation scheme of transcoding and streaming (I)