当前位置:网站首页>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;
}
};
边栏推荐
- 自动化测试的好处
- About some basic DP -- those things about coins (the basic introduction of DP)
- P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
- MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
- Comprehensive ability evaluation system
- 【按鍵消抖】基於FPGA的按鍵消抖模塊開發
- Path of class file generated by idea compiling JSP page
- DM8 archive log file manual switching
猜你喜欢
记一次excel XXE漏洞
How to modify field constraints (type, default, null, etc.) in a table
Mysql数据库慢sql抓取与分析
Thread sleep, thread sleep application scenarios
Record an excel xxE vulnerability
[tomato assistant installation]
lora网关以太网传输
[Zhao Yuqiang] deploy kubernetes cluster with binary package
In Net 6 CS more concise method
Practical development of member management applet 06 introduction to life cycle function and user-defined method
随机推荐
Determine which week of the month the day is
[Key shake elimination] development of key shake elimination module based on FPGA
Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
Comprehensive ability evaluation system
Lora gateway Ethernet transmission
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
QML和QWidget混合开发(初探)
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
Prime protocol announces cross chain interconnection applications on moonbeam
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
About some basic DP -- those things about coins (the basic introduction of DP)
颠覆你的认知?get和post请求的本质
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
Cf464e the classic problem [shortest path, chairman tree]
About some basic DP -- those things about coins (the basic introduction of DP)
pd. to_ numeric
Viewing and verifying backup sets using dmrman
Data processing methods - smote series and adasyn
Basic knowledge of binary tree, BFC, DFS
Slow SQL fetching and analysis of MySQL database