Skip to content

Commit

Permalink
fix: 统计整数数目
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-ge committed Jan 16, 2024
1 parent 6ab8aeb commit e404d0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/math/count_of_integers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ class Solution {
for (char c : num1)
down_limit.push_back(c - '0');

std::function<int(int, int, bool, bool, bool)> f;
std::function<int(int, long long, bool, bool, bool)> f;
std::unordered_map<long long, int> memo;

f = [&](int i, int s, bool valid, bool dlimit, bool ulimit) -> int {
f = [&](int i, long long s, bool valid, bool dlimit, bool ulimit) -> int {
if (i == m) {
return valid && min_sum <= s && s <= max_sum ? 1 : 0;
}
long long key =
i + 71LL * (s + 71LL * (valid + 2LL * (dlimit + 2LL * ulimit)));
i + 1001LL * (s + 1001LL * (valid + 2LL * (dlimit + 2LL * ulimit)));
if (memo.count(key))
return memo[key];
int down = dlimit ? down_limit[i] : 0;
int up = ulimit ? up_limit[i] : 9;
int ans = 0;
for (int d = down; d <= up; ++d) {
ans = (ans + f(i + 1, s + d, valid || d != 0, dlimit && d == down,
ulimit && d == up)) %
ans = (ans + f(i + 1, (s + d) % mod, valid || d != 0,
dlimit && d == down, ulimit && d == up)) %
mod;
}
return memo[key] = ans;
Expand Down
2 changes: 1 addition & 1 deletion test/lib/lib_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 执行编译时间:2024-01-16 09:18:43
// 执行编译时间:2024-01-16 09:32:34
#include <gtest/gtest.h>
#include <lib.hpp>

Expand Down

0 comments on commit e404d0f

Please sign in to comment.