摘要: 快速幂。 class Solution { public: double qpow(double x, long long n) { double res = 1; while (n) { if (n & 1) res *= x; x = x * x; n >>= 1; } return res; 阅读全文
posted @ 2021-07-21 20:27 Dazzling! 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 方法一:动态规划 对于的正整数 \(n\),当 \(n \ge 2\) 时,可以拆分成至少两个正整数的和。令 \(k\) 是拆分出的第一个正整数,则剩下的部分是 \(n-k\),\(n-k\) 可以不继续拆分,或者继续拆分成至少两个正整数的和。由于每个正整数对应的最大乘积取决于比它小的正整数对应的最 阅读全文
posted @ 2021-07-21 12:49 Dazzling! 阅读(155) 评论(0) 推荐(0) 编辑
摘要: DFS。 class Solution { public: int n, m; int single_sum(int x) { int res = 0; while (x) { res += x % 10; x /= 10; } return res; } int sum(int x, int y) 阅读全文
posted @ 2021-07-21 11:21 Dazzling! 阅读(16) 评论(0) 推荐(0) 编辑
摘要: 回溯法。 class Solution { public: int n, m; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; bool check(int x, int y) { return x >= 0 && x < n && y >= 0 阅读全文
posted @ 2021-07-21 10:46 Dazzling! 阅读(18) 评论(0) 推荐(0) 编辑