当前位置:网站首页>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;
}
};
边栏推荐
- 综合能力测评系统
- DM8 archive log file manual switching
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- 2/11 matrix fast power +dp+ bisection
- P3500 [POI2010]TES-Intelligence Test(二分&离线)
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- P2648 make money
- [Key shake elimination] development of key shake elimination module based on FPGA
- Unity中几个重要类
猜你喜欢
Record the pit of NETCORE's memory surge
DM8 backup set deletion
1291_ Add timestamp function in xshell log
How does technology have the ability to solve problems perfectly
颠覆你的认知?get和post请求的本质
One question per day (Mathematics)
C (XXIX) C listbox CheckedListBox Imagelist
10个 Istio 流量管理 最常用的例子,你知道几个?
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
DM8 archive log file manual switching
随机推荐
Mysql数据库慢sql抓取与分析
Cross domain and jsonp details
10个 Istio 流量管理 最常用的例子,你知道几个?
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
MySQL master-slave replication
POI add border
C (thirty) C combobox listview TreeView
C mouse event and keyboard event of C (XXVIII)
Leetcode32 longest valid bracket (dynamic programming difficult problem)
【leetcode】1189. Maximum number of "balloons"
Class A, B, C networks and subnet masks in IPv4
1291_ Add timestamp function in xshell log
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
Record the pit of NETCORE's memory surge
Execution order of scripts bound to game objects
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
User datagram protocol UDP
Solution to the problem that the root account of MySQL database cannot be logged in remotely