当前位置:网站首页>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;
}
};
边栏推荐
- 深入浅出node模板解析错误escape is not a function
- Figure application details
- MySQL about self growth
- Recommendation system (IX) PNN model (product based neural networks)
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- ESP32_ FreeRTOS_ Arduino_ 1_ Create task
- C mouse event and keyboard event of C (XXVIII)
- 1291_ Add timestamp function in xshell log
- Custom event of C (31)
- Conditionally [jsonignore]
猜你喜欢
![[001] [stm32] how to download STM32 original factory data](/img/5a/02d87fe1409a9427180ecefb8326c6.jpg)
[001] [stm32] how to download STM32 original factory data
![[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos](/img/41/27ce3741ef29e87c0f3b954fdef87a.png)
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos

AcWing 243. A simple integer problem 2 (tree array interval modification interval query)

Viewing and verifying backup sets using dmrman

查询mysql数据库中各表记录数大小

Proof of Stirling formula

Recommendation system (IX) PNN model (product based neural networks)
![[Key shake elimination] development of key shake elimination module based on FPGA](/img/47/c3833c077ad89d4906e425ced945bb.png)
[Key shake elimination] development of key shake elimination module based on FPGA

Comprehensive ability evaluation system
![Mlapi series - 04 - network variables and network serialization [network synchronization]](/img/fc/aebbad5295481788de5c1fdb432a77.jpg)
Mlapi series - 04 - network variables and network serialization [network synchronization]
随机推荐
E. Best Pair
Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
In depth MySQL transactions, stored procedures and triggers
About some basic DP -- those things about coins (the basic introduction of DP)
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
Web components series (VII) -- life cycle of custom components
HotSpot VM
POI add border
Figure application details
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
51nod 1130 n factorial length V2 (Stirling approximation)
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
1291_ Add timestamp function in xshell log
2/12 didn't learn anything
What is the difference between gateway address and IP address in tcp/ip protocol?
80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
Record an excel xxE vulnerability
Benefits of automated testing
2/13 review Backpack + monotonic queue variant
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0