当前位置:网站首页>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;
}
};
边栏推荐
- hashlimit速率控制
- Query the number and size of records in each table in MySQL database
- TCP/IP协议里面的网关地址和ip地址有什么区别?
- ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
- P2648 make money
- HotSpot VM
- lora网关以太网传输
- C (thirty) C combobox listview TreeView
- 脚本生命周期
- Prime protocol announces cross chain interconnection applications on moonbeam
猜你喜欢
20、 EEPROM memory (AT24C02) (similar to AD)
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Data processing methods - smote series and adasyn
Benefits of automated testing
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
Record an excel xxE vulnerability
DM8 archive log file manual switching
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
随机推荐
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
Mysql数据库慢sql抓取与分析
Python book learning notes - Chapter 09 section 01 create and use classes
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
Brief tutorial for soft exam system architecture designer | general catalog
Tips for using dm8huge table
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
Record an excel xxE vulnerability
Slow SQL fetching and analysis of MySQL database
【leetcode】22. bracket-generating
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Proof of Stirling formula
Viewing and verifying backup sets using dmrman
HotSpot VM
Explain in simple terms node template parsing error escape is not a function
[tomato assistant installation]
asp. Core is compatible with both JWT authentication and cookies authentication
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
pd. to_ numeric