当前位置:网站首页>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;
}
};
边栏推荐
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- Security xxE vulnerability recurrence (XXe Lab)
- Python book learning notes - Chapter 09 section 01 create and use classes
- Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- /usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- 2/12 didn't learn anything
- 10个 Istio 流量管理 最常用的例子,你知道几个?
猜你喜欢
CertBot 更新证书失败解决
Viewing and verifying backup sets using dmrman
Cross domain and jsonp details
Maxay paper latex template description
About some basic DP -- those things about coins (the basic introduction of DP)
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Mlapi series - 04 - network variables and network serialization [network synchronization]
Ipv4中的A 、B、C类网络及子网掩码
Lombok principle and the pit of ⽤ @data and @builder at the same time
[tomato assistant installation]
随机推荐
Stable Huawei micro certification, stable Huawei cloud database service practice
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Record the pit of NETCORE's memory surge
Codeforces Round #770 (Div. 2) B. Fortune Telling
Recommendation system (IX) PNN model (product based neural networks)
电脑钉钉怎么调整声音
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Record an excel xxE vulnerability
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
2328. 网格图中递增路径的数目(记忆化搜索)
VNCTF2022 WriteUp
CertBot 更新证书失败解决
2/11 matrix fast power +dp+ bisection
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
2/12 didn't learn anything
C (XXIX) C listbox CheckedListBox Imagelist
P2022 有趣的数(二分&数位dp)
TCP/IP协议里面的网关地址和ip地址有什么区别?