Re: [闲聊] 每日LeetCode

楼主: oin1104 (是oin的说)   2024-01-26 21:53:18
我比较暴力一点
直接在外面多弄一圈
然后每次都用备用阵列看下一步能走到哪里
然后同时把外面那圈加起来就是答案
我感觉明天要hard了
呜呜呜哇哇哇哇哇哇
class Solution {
public:
int findPaths(int m, int n, int maxMove, int startRow, int startColumn)
{
vector<vector<long long>> paper(m+2 ,vector<long long>(n+2 , 0));
vector<vector<long long>> paper2(m+2 ,vector<long long>(n+2 , 0));
paper[startRow+1][startColumn+1] = 1;
long long pans = 0;
for(int r = 0 ; r < maxMove ; r ++)
{
for(int i = 0 ; i <= m+1 ; i ++)
{
for(int j = 0 ; j <= n+1 ; j ++)
{
paper2[i][j] = 0;
}
}
for(int i = 1 ; i <= m ; i ++)
{
for(int j = 1 ; j <= n ; j ++)
{
long long k = paper[i][j];
k = k % 1000000007;
paper2[i-1][j] += k;
paper2[i+1][j] += k;
paper2[i][j-1] += k;
paper2[i][j+1] += k;
}
}
for(int i = 0 ; i <= m+1 ; i ++)
{
pans += paper2[i][0];
pans = pans % 1000000007;
pans += paper2[i][n+1];
pans = pans % 1000000007;
}
for(int i = 0 ; i <= n+1 ; i ++)
{
pans += paper2[0][i];
pans = pans % 1000000007;
pans += paper2[m+1][i];
pans = pans % 1000000007;
}
// for(int i = 0 ; i <= m+1 ; i ++)
// {
// for(int j = 0 ; j <= n+1 ; j ++)
// {
// printf("%d ",paper2[i][j]);
// }
// printf("\n");
// }
// printf("========\n");
paper = paper2;
}
int ans = pans % 1000000007;
return ans;
}
};
作者: sustainer123 (caster)   2024-01-26 21:55:00
大师
作者: JIWP (JIWP)   2024-01-26 22:03:00
你版剩我不会写每日了

Links booklink

Contact Us: admin [ a t ] ucptt.com