mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-21 21:16:45 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code> 和一个整数 <code>numSlots</code> ,满足<code>2 * numSlots >= n</code> 。总共有 <code>numSlots</code> 个篮子,编号为 <code>1</code> 到 <code>numSlots</code> 。</p>\n\n<p>你需要把所有 <code>n</code> 个整数分到这些篮子中,且每个篮子 <strong>至多</strong> 有 2 个整数。一种分配方案的 <strong>与和</strong> 定义为每个数与它所在篮子编号的 <strong>按位与运算</strong> 结果之和。</p>\n\n<ul>\n\t<li>比方说,将数字 <code>[1, 3]</code> 放入篮子 <strong><em><code>1</code></em></strong> 中,<code>[4, 6]</code> 放入篮子 <strong><em><code>2</code></em></strong> 中,这个方案的与和为 <code>(1 AND <strong><em>1</em></strong>) + (3 AND <strong><em>1</em></strong>) + (4 AND <em><strong>2</strong></em>) + (6 AND <em><strong>2</strong></em>) = 1 + 1 + 0 + 2 = 4</code> 。</li>\n</ul>\n\n<p>请你返回将 <code>nums</code> 中所有数放入<em> </em><code>numSlots</code> 个篮子中的最大与和。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><b>输入:</b>nums = [1,2,3,4,5,6], numSlots = 3\n<b>输出:</b>9\n<b>解释:</b>一个可行的方案是 [1, 4] 放入篮子 <em><strong>1</strong></em> 中,[2, 6] 放入篮子 <strong><em>2</em></strong> 中,[3, 5] 放入篮子 <strong><em>3</em></strong> 中。\n最大与和为 (1 AND <strong><em>1</em></strong>) + (4 AND <strong><em>1</em></strong>) + (2 AND <strong><em>2</em></strong>) + (6 AND <strong><em>2</em></strong>) + (3 AND <strong><em>3</em></strong>) + (5 AND <em><strong>3</strong></em>) = 1 + 0 + 2 + 2 + 3 + 1 = 9 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>nums = [1,3,10,4,7,1], numSlots = 9\n<b>输出:</b>24\n<b>解释:</b>一个可行的方案是 [1, 1] 放入篮子 <em><strong>1</strong></em> 中,[3] 放入篮子 <em><strong>3</strong></em> 中,[4] 放入篮子 <strong><em>4</em></strong> 中,[7] 放入篮子 <strong><em>7</em></strong> 中,[10] 放入篮子 <strong><em>9</em></strong> 中。\n最大与和为 (1 AND <strong><em>1</em></strong>) + (1 AND <strong><em>1</em></strong>) + (3 AND <strong><em>3</em></strong>) + (4 AND <strong><em>4</em></strong>) + (7 AND <strong><em>7</em></strong>) + (10 AND <strong><em>9</em></strong>) = 1 + 1 + 3 + 4 + 7 + 8 = 24 。\n注意,篮子 2 ,5 ,6 和 8 是空的,这是允许的。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == nums.length</code></li>\n\t<li><code>1 <= numSlots <= 9</code></li>\n\t<li><code>1 <= n <= 2 * numSlots</code></li>\n\t<li><code>1 <= nums[i] <= 15</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 35,
|
||||
"likes": 36,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"6.5K\", \"totalAcceptedRaw\": 3063, \"totalSubmissionRaw\": 6547, \"acRate\": \"46.8%\"}",
|
||||
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"6.6K\", \"totalAcceptedRaw\": 3077, \"totalSubmissionRaw\": 6575, \"acRate\": \"46.8%\"}",
|
||||
"hints": [
|
||||
"Can you think of a dynamic programming solution to this problem?",
|
||||
"Can you use a bitmask to represent the state of the slots?"
|
||||
|
Reference in New Issue
Block a user