当前位置:网站首页>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;
}
};
边栏推荐
- [FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- E. Best Pair
- 绑定在游戏对象上的脚本的执行顺序
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
- Tips for using dm8huge table
- MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- 2328. 网格图中递增路径的数目(记忆化搜索)
猜你喜欢

Execution order of scripts bound to game objects

Redis (replicate dictionary server) cache

Chinese brand hybrid technology: there is no best technical route, only better products

Deep learning framework installation (tensorflow & pytorch & paddlepaddle)

What is the difference between gateway address and IP address in tcp/ip protocol?
![[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

SSTI template injection explanation and real problem practice
![[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

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

Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
随机推荐
Hashcode and equals
SSTI template injection explanation and real problem practice
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Brief tutorial for soft exam system architecture designer | general catalog
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
自动化测试的好处
2/11 matrix fast power +dp+ bisection
User datagram protocol UDP
2327. 知道秘密的人数(递推)
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
记一次excel XXE漏洞
Stack and queue
【leetcode】1189. Maximum number of "balloons"
Overturn your cognition? The nature of get and post requests
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
BOM - location, history, pop-up box, timing
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
C (thirty) C combobox listview TreeView
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》