当前位置:网站首页>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;
}
};
边栏推荐
- 20、 EEPROM memory (AT24C02) (similar to AD)
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- asp. Core is compatible with both JWT authentication and cookies authentication
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- MySql數據庫root賬戶無法遠程登陸解决辦法
- DM8 backup set deletion
- Data processing methods - smote series and adasyn
- [disassembly] a visual air fryer. By the way, analyze the internal circuit
- Hashcode and equals
猜你喜欢
【FPGA教程案例11】基于vivado核的除法器设计与实现
[tomato assistant installation]
[Key shake elimination] development of key shake elimination module based on FPGA
Stable Huawei micro certification, stable Huawei cloud database service practice
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Class A, B, C networks and subnet masks in IPv4
User datagram protocol UDP
Basic use of MySQL (it is recommended to read and recite the content)
综合能力测评系统
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
随机推荐
Security xxE vulnerability recurrence (XXe Lab)
hashlimit速率控制
C form application of C (27)
P2648 make money
Path of class file generated by idea compiling JSP page
Thread sleep, thread sleep application scenarios
食品行业仓储条码管理系统解决方案
图应用详解
Ks003 mall system based on JSP and Servlet
How to execute an SQL statement in MySQL
记一次excel XXE漏洞
Basic use of MySQL (it is recommended to read and recite the content)
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
2/11 matrix fast power +dp+ bisection
Stable Huawei micro certification, stable Huawei cloud database service practice
Viewing and verifying backup sets using dmrman
脚本生命周期
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
Cross domain and jsonp details
Redis (replicate dictionary server) cache