当前位置:网站首页>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;
}
};
边栏推荐
- Prime protocol announces cross chain interconnection applications on moonbeam
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- [001] [stm32] how to download STM32 original factory data
- 颠覆你的认知?get和post请求的本质
- MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
- math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- Slow SQL fetching and analysis of MySQL database
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Unity中几个重要类
猜你喜欢
![[tomato assistant installation]](/img/06/672a616d4fc2a43b83054eb1057628.jpg)
[tomato assistant installation]

IDEA编译JSP页面生成的class文件路径

Detailed explanation of serialization and deserialization

Chinese brand hybrid technology: there is no best technical route, only better products
![[001] [stm32] how to download STM32 original factory data](/img/5a/02d87fe1409a9427180ecefb8326c6.jpg)
[001] [stm32] how to download STM32 original factory data

题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》

TCP/IP协议里面的网关地址和ip地址有什么区别?

DM8 archive log file manual switching

Stable Huawei micro certification, stable Huawei cloud database service practice

MySql数据库root账户无法远程登陆解决办法
随机推荐
In depth MySQL transactions, stored procedures and triggers
Determine which week of the month the day is
Slow SQL fetching and analysis of MySQL database
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
asp. Core is compatible with both JWT authentication and cookies authentication
Brief tutorial for soft exam system architecture designer | general catalog
About some basic DP -- those things about coins (the basic introduction of DP)
Detailed explanation of serialization and deserialization
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
Query the number and size of records in each table in MySQL database
Lombok原理和同时使⽤@Data和@Builder 的坑
Conditionally [jsonignore]
Explain in simple terms node template parsing error escape is not a function
Benefits of automated testing
Python book learning notes - Chapter 09 section 01 create and use classes
[FPGA tutorial case 11] design and implementation of divider based on vivado core
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did