Skip to content

Commit 0981691

Browse files
authored
update: 添加问题“2044.统计按位或能得到最大值的子集数目”的代码和题解(#1049)
* 3202: O(k)空间 - AC.cpp+py (#1035) (#1041) cpp - AC,44.38%,64.27% cpp(no max) - AC,46.19%,67.47% py(no max - AC,61.42%,81.68% * word: en 2025.07.22 (#1035) (#1041) * 3202: O(k)空间 - AC.go+docs (#1035) (#1041) go - AC,17.49%,80.21% * 3202: docs-题解 (#1035) (#1041) * MGJW: git pull (#1046) - by others .pem泄露无所谓 反正为了指标的HTTPS只是一个笑话 * MGJW: test 150 times (#1046) 研二这个点加班的就我一个 - 这绝对有问题 * MGJW: once then once (#1046) 完成一个需求就会有下一个需求 * docs: 毕设月报 (#1046) 毁灭吧 世界 * MGJW: webex (#1046) 还挺快 * MGJW: git pull (#1046) by hand ofcoursely * MGJW: owa beacon generator (#1046) 看吧 我就说还有 * docs: 毕设月报 (#1046) 吃饭去 * log: 快快快 #1046 * docs: 毕设月报+en words (#1046) * docs: english words - 上周五 (#1046) * docs: 今日日语(+英语) words * 2044: init (#1048) 练习git merge之冲突解决呢是吧 * 2044: AC.cpp (#1048) cpp - AC,45.45%,35.35% * 2044: WA.cpp - DFS回溯 (#1048) * 2044: WA.cpp - DFS回溯 (#1048) * 2044: WA.cpp - DFS回溯 (#1048) * 2044: AC.cpp - DFS回溯 (#1048) cpp - AC,95.96%,89.90% * 2044: AC.cpp - DFS回溯 - 剪枝 (#1048) cpp - AC,100.00%,77.78% * 2044: WA.go - DFS回溯 - 剪枝 (#1048) * 2044: AC.go+py - DFS回溯 - 剪枝 (#1048) go - AC,100.00%,73.68% py - AC,88.09%,83.33% java - AC,95.77%,78.87% * update: 添加问题“2044.统计按位或能得到最大值的子集数目”的代码和题解(#1049) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent 34ff65e commit 0981691

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5295
-49
lines changed

.gitlog

Lines changed: 310 additions & 48 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-28 19:30:16
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-28 19:51:20
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
int ans = 0;
14+
int maxium = 0;
15+
vector<int> nums;
16+
17+
void dfs(int th, int now) {
18+
if (now == maxium) {
19+
ans += 1 << (nums.size() - th);
20+
return;
21+
}
22+
if (th == nums.size()) {
23+
return;
24+
}
25+
dfs(th + 1, now);
26+
dfs(th + 1, now | nums[th]);
27+
}
28+
public:
29+
int countMaxOrSubsets(vector<int>& nums) {
30+
for (int t : nums) {
31+
maxium |= t;
32+
}
33+
this->nums = move(nums);
34+
dfs(0, 0);
35+
return ans;
36+
}
37+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-28 13:38:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-28 20:31:11
6+
*/
7+
package main
8+
9+
// import "fmt"
10+
11+
var ans2044, maxium2044 int = 0, 0
12+
var nums2044 []int
13+
14+
func dfs2044(th, now int) {
15+
if now == maxium2044 {
16+
ans2044 += 1 << (len(nums2044) - th)
17+
return
18+
}
19+
if th == len(nums2044) {
20+
return
21+
}
22+
dfs2044(th + 1, now)
23+
dfs2044(th + 1, now | nums2044[th])
24+
}
25+
26+
func countMaxOrSubsets(nums []int) int {
27+
nums2044 = nums
28+
ans2044 = 0
29+
maxium2044 = 0
30+
for _, t := range nums {
31+
maxium2044 |= t
32+
}
33+
dfs2044(0, 0)
34+
return ans2044
35+
}
36+
37+
// func main() {
38+
// fmt.Println(countMaxOrSubsets([]int{2, 2, 2}))
39+
// }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-28 13:38:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-28 20:43:13
6+
*/
7+
class Solution {
8+
private int ans = 0;
9+
private int M = 0;
10+
private int[] nums;
11+
12+
private void dfs(int th, int now) {
13+
if (now == M) {
14+
ans += 1 << (nums.length - th);
15+
return;
16+
}
17+
if (th == nums.length) {
18+
return;
19+
}
20+
dfs(th + 1, now);
21+
dfs(th + 1, now | nums[th]);
22+
}
23+
24+
public int countMaxOrSubsets(int[] nums) {
25+
this.nums = nums;
26+
for (int t : nums) {
27+
M |= t;
28+
}
29+
dfs(0, 0);
30+
return ans;
31+
}
32+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-07-28 13:38:06
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-07-28 20:40:58
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def dfs(self, th: int, now: int) -> None:
11+
if now == self.M:
12+
self.ans += 1 << (len(self.nums) - th)
13+
return
14+
if th == len(self.nums):
15+
return
16+
self.dfs(th + 1, now)
17+
self.dfs(th + 1, now | self.nums[th])
18+
19+
def countMaxOrSubsets(self, nums: List[int]) -> int:
20+
self.ans = 0
21+
self.nums = nums
22+
self.M = 0
23+
for t in nums:
24+
self.M |= t
25+
self.dfs(0, 0)
26+
return self.ans
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-28 19:30:16
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-28 19:50:18
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
private:
13+
int ans = 0;
14+
int maxium = 0;
15+
vector<int> nums;
16+
17+
void dfs(int th, int now) {
18+
if (th == nums.size()) {
19+
ans += now == maxium;
20+
return;
21+
}
22+
dfs(th + 1, now);
23+
dfs(th + 1, now | nums[th]);
24+
}
25+
public:
26+
int countMaxOrSubsets(vector<int>& nums) {
27+
for (int t : nums) {
28+
maxium |= t;
29+
}
30+
this->nums = move(nums);
31+
dfs(0, 0);
32+
return ans;
33+
}
34+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-28 13:38:06
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-28 18:51:34
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int countMaxOrSubsets(vector<int>& nums) {
14+
int maxium = 0;
15+
for (int t : nums) {
16+
maxium |= t;
17+
}
18+
int ans = 0;
19+
int n = nums.size(), mask = 1 << n;
20+
for (int i = 0; i < mask; i++) {
21+
int thisVal = 0;
22+
for (int j = 0; j < n; j++) {
23+
if (i >> j & 1) {
24+
thisVal |= nums[j];
25+
}
26+
}
27+
ans += thisVal == maxium;
28+
}
29+
return ans;
30+
}
31+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@
667667
|2034.股票价格波动|中等|<a href="https://leetcode.cn/problems/stock-price-fluctuation/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/10/08/LeetCode%202034.%E8%82%A1%E7%A5%A8%E4%BB%B7%E6%A0%BC%E6%B3%A2%E5%8A%A8/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/133677649" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/stock-price-fluctuation/solutions/2472177/letmefly-2034gu-piao-jie-ge-bo-dong-ha-x-w3w4/" target="_blank">LeetCode题解</a>|
668668
|2037.使每位学生都有座位的最少移动次数|简单|<a href="https://leetcode.cn/problems/minimum-number-of-moves-to-seat-everyone/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2022/12/31/LeetCode%202037.%E4%BD%BF%E6%AF%8F%E4%BD%8D%E5%AD%A6%E7%94%9F%E9%83%BD%E6%9C%89%E5%BA%A7%E4%BD%8D%E7%9A%84%E6%9C%80%E5%B0%91%E7%A7%BB%E5%8A%A8%E6%AC%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/128509361" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-number-of-moves-to-seat-everyone/solutions/2039583/letmefly-2037shi-mei-wei-xue-sheng-du-yo-2gpy/" target="_blank">LeetCode题解</a>|
669669
|2042.检查句子中的数字是否递增|简单|<a href="https://leetcode.cn/problems/check-if-numbers-are-ascending-in-a-sentence/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/01/03/LeetCode%202042.%E6%A3%80%E6%9F%A5%E5%8F%A5%E5%AD%90%E4%B8%AD%E7%9A%84%E6%95%B0%E5%AD%97%E6%98%AF%E5%90%A6%E9%80%92%E5%A2%9E/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/128538008" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/check-if-numbers-are-ascending-in-a-sentence/solutions/2043292/letmefly-2042jian-cha-ju-zi-zhong-de-shu-5leg/" target="_blank">LeetCode题解</a>|
670+
|2044.统计按位或能得到最大值的子集数目|中等|<a href="https://leetcode.cn/problems/count-number-of-maximum-bitwise-or-subsets/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/28/LeetCode%202044.%E7%BB%9F%E8%AE%A1%E6%8C%89%E4%BD%8D%E6%88%96%E8%83%BD%E5%BE%97%E5%88%B0%E6%9C%80%E5%A4%A7%E5%80%BC%E7%9A%84%E5%AD%90%E9%9B%86%E6%95%B0%E7%9B%AE/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149725900" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-number-of-maximum-bitwise-or-subsets/solutions/3736072/letmefly-2044tong-ji-an-wei-huo-neng-de-97g9f/" target="_blank">LeetCode题解</a>|
670671
|2048.下一个更大的数值平衡数|中等|<a href="https://leetcode.cn/problems/next-greater-numerically-balanced-number/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/12/09/LeetCode%202048.%E4%B8%8B%E4%B8%80%E4%B8%AA%E6%9B%B4%E5%A4%A7%E7%9A%84%E6%95%B0%E5%80%BC%E5%B9%B3%E8%A1%A1%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/134900679" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/next-greater-numerically-balanced-number/solutions/2560353/letmefly-2048xia-yi-ge-geng-da-de-shu-zh-7p4t/" target="_blank">LeetCode题解</a>|
671672
|2050.并行课程III|困难|<a href="https://leetcode.cn/problems/parallel-courses-iii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/07/28/LeetCode%202050.%E5%B9%B6%E8%A1%8C%E8%AF%BE%E7%A8%8BIII/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/131973511" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/parallel-courses-iii/solutions/2362142/letmefly-2050bing-xing-ke-cheng-iiidfs-b-9tuc/" target="_blank">LeetCode题解</a>|
672673
|2065.最大化一张图中的路径价值|困难|<a href="https://leetcode.cn/problems/maximum-path-quality-of-a-graph/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/07/01/LeetCode%202065.%E6%9C%80%E5%A4%A7%E5%8C%96%E4%B8%80%E5%BC%A0%E5%9B%BE%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84%E4%BB%B7%E5%80%BC/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/140101479" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-path-quality-of-a-graph/solutions/2827788/letmefly-2065zui-da-hua-yi-zhang-tu-zhon-vvkl/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)