'commit'
This commit is contained in:
26
GESP/Level6/20240301_dfs.cpp
Normal file
26
GESP/Level6/20240301_dfs.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N = 200010;
|
||||
LL q[N]; // 记忆化
|
||||
LL n, c, b, a;
|
||||
|
||||
const int MOD = 1e9 + 7; // 模 1e9+7
|
||||
|
||||
LL dfs(LL x) {
|
||||
// 走到头了,此时只有一种方案
|
||||
if (x <= c)
|
||||
return 1;
|
||||
// 如果搜索过,直接返回,不再重复计算
|
||||
if (q[x])
|
||||
return q[x];
|
||||
|
||||
// 如果没有进行搜索就需要计算了
|
||||
return q[x] = (dfs(x - a) % MOD + dfs(x - b) % MOD) % MOD;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> a >> b >> c;
|
||||
cout << dfs(n);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user