当前位置:网站首页>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;
}
};
边栏推荐
- C form application of C (27)
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- 自动化测试的好处
- Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 2/12 didn't learn anything
- How many of the 10 most common examples of istio traffic management do you know?
- 2/11 matrix fast power +dp+ bisection
- Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Développement d'un module d'élimination des bavardages à clé basé sur la FPGA

ESP32_ FreeRTOS_ Arduino_ 1_ Create task
![[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)](/img/8a/068faf3e8de642c9e3c4118e6084aa.jpg)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)

MySql數據庫root賬戶無法遠程登陸解决辦法

When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation

How to modify field constraints (type, default, null, etc.) in a table

C mouse event and keyboard event of C (XXVIII)

Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes

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

绑定在游戏对象上的脚本的执行顺序
随机推荐
Brief tutorial for soft exam system architecture designer | general catalog
Mysql数据库慢sql抓取与分析
POI add border
Security xxE vulnerability recurrence (XXe Lab)
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
HotSpot VM
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Detailed explanation of serialization and deserialization
Leetcode32 longest valid bracket (dynamic programming difficult problem)
Tips for using dm8huge table
How to execute an SQL statement in MySQL
Ipv4中的A 、B、C类网络及子网掩码
2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
Database, relational database and NoSQL non relational database
Thread sleep, thread sleep application scenarios
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
Basic use of MySQL (it is recommended to read and recite the content)
脚本生命周期
SSTI template injection explanation and real problem practice
QML和QWidget混合开发(初探)