当前位置:网站首页>2328. 网格图中递增路径的数目(记忆化搜索)
2328. 网格图中递增路径的数目(记忆化搜索)
2022-07-06 04:11:00 【Harris-H】
2328. 网格图中递增路径的数目(记忆化搜索)
原理矩阵的四周扩散,也可以记忆化dp。
时间复杂度: O ( n m ) O(nm) O(nm)
class Solution {
public:
int countPaths(vector<vector<int>>& a) {
int n =a.size(),m=a[0].size();
vector<vector<int> >f(n,vector<int>(m,-1));
int d[4][2] ={
0,1,0,-1,1,0,-1,0};
const int mod = 1e9+7;
function<int(int,int)> dfs = [&](int x,int y){
if(~f[x][y]) return f[x][y];
int ans = 1;
for(int i=0;i<4;i++){
int nx = x+d[i][0],ny=y+d[i][1];
if(nx>=0 && nx<n && ny>=0 && ny<m && a[nx][ny] >a[x][y]){
ans=(ans+dfs(nx,ny))%mod;
}
}
return f[x][y] =ans;
};
int ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++) ans=(ans+dfs(i,j))%mod;
return ans;
}
};
边栏推荐
- POI add border
- [001] [stm32] how to download STM32 original factory data
- Basic use of MySQL (it is recommended to read and recite the content)
- Ks003 mall system based on JSP and Servlet
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
- 绑定在游戏对象上的脚本的执行顺序
- Viewing and verifying backup sets using dmrman
- Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
猜你喜欢

Yyds dry goods inventory web components series (VII) -- life cycle of custom components

Security xxE vulnerability recurrence (XXe Lab)
![[disassembly] a visual air fryer. By the way, analyze the internal circuit](/img/73/29553d60f47deadfff420be40b7f77.jpg)
[disassembly] a visual air fryer. By the way, analyze the internal circuit

【按键消抖】基于FPGA的按键消抖模块开发

Interface idempotency

MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】

Stable Huawei micro certification, stable Huawei cloud database service practice

Benefits of automated testing

Solution of storage bar code management system in food industry

Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
随机推荐
自动化测试的好处
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Basic knowledge of binary tree, BFC, DFS
HotSpot VM
DM8 backup set deletion
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
【leetcode】22. bracket-generating
Prime protocol announces cross chain interconnection applications on moonbeam
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Benefits of automated testing
【FPGA教程案例11】基于vivado核的除法器设计与实现
asp. Core is compatible with both JWT authentication and cookies authentication
Execution order of scripts bound to game objects
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
Basic use of MySQL (it is recommended to read and recite the content)
Cf464e the classic problem [shortest path, chairman tree]
综合能力测评系统
脚本生命周期