当前位置:网站首页>2328. Number of incremental paths in the grid graph (memory search)
2328. Number of incremental paths in the grid graph (memory search)
2022-07-06 04:15:00 【Harris-H】
2328. The number of incremental paths in the grid graph ( Memory search )
Diffusion around the principle matrix , It can also be memorized dp.
Time complexity : 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;
}
};
边栏推荐
- How does technology have the ability to solve problems perfectly
- Tips for using dm8huge table
- 深入浅出node模板解析错误escape is not a function
- Path of class file generated by idea compiling JSP page
- 2327. 知道秘密的人数(递推)
- HotSpot VM
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- HotSpot VM
- asp. Core is compatible with both JWT authentication and cookies authentication
- One question per day (Mathematics)
猜你喜欢

What is the difference between gateway address and IP address in tcp/ip protocol?

Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage

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

Detailed explanation of serialization and deserialization

math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)

Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM

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

Comprehensive ability evaluation system

记一次excel XXE漏洞

电脑钉钉怎么调整声音
随机推荐
DM8 backup set deletion
P2648 make money
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
Custom event of C (31)
Solve the compilation problem of "c2001: line breaks in constants"
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
User datagram protocol UDP
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Basic use of MySQL (it is recommended to read and recite the content)
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Python book learning notes - Chapter 09 section 01 create and use classes
2328. 网格图中递增路径的数目(记忆化搜索)
MySql數據庫root賬戶無法遠程登陸解决辦法
Determine which week of the month the day is
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Execution order of scripts bound to game objects
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
C (thirty) C combobox listview TreeView
Data processing methods - smote series and adasyn
Use js to complete an LRU cache