mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 05:26:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个整数 <code>n</code> 表示某所大学里课程的数目,编号为 <code>1</code> 到 <code>n</code> ,数组 <code>dependencies</code> 中, <code>dependencies[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> 表示一个先修课的关系,也就是课程 <code>x<sub>i</sub></code> 必须在课程 <code>y<sub>i</sub></code><sub> </sub>之前上。同时你还有一个整数 <code>k</code> 。</p>\n\n<p>在一个学期中,你 <strong>最多</strong> 可以同时上 <code>k</code> 门课,前提是这些课的先修课在之前的学期里已经上过了。</p>\n\n<p>请你返回上完所有课最少需要多少个学期。题目保证一定存在一种上完所有课的方式。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/06/27/leetcode_parallel_courses_1.png\" style=\"height: 164px; width: 300px;\"></strong></p>\n\n<pre><strong>输入:</strong>n = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2\n<strong>输出:</strong>3 \n<strong>解释:</strong>上图展示了题目输入的图。在第一个学期中,我们可以上课程 2 和课程 3 。然后第二个学期上课程 1 ,第三个学期上课程 4 。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/06/27/leetcode_parallel_courses_2.png\" style=\"height: 234px; width: 300px;\"></strong></p>\n\n<pre><strong>输入:</strong>n = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2\n<strong>输出:</strong>4 \n<strong>解释:</strong>上图展示了题目输入的图。一个最优方案是:第一学期上课程 2 和 3,第二学期上课程 4 ,第三学期上课程 1 ,第四学期上课程 5 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>n = 11, dependencies = [], k = 2\n<strong>输出:</strong>6\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= n <= 15</code></li>\n\t<li><code>1 <= k <= n</code></li>\n\t<li><code>0 <= dependencies.length <= n * (n-1) / 2</code></li>\n\t<li><code>dependencies[i].length == 2</code></li>\n\t<li><code>1 <= x<sub>i</sub>, y<sub>i</sub> <= n</code></li>\n\t<li><code>x<sub>i</sub> != y<sub>i</sub></code></li>\n\t<li>所有先修关系都是不同的,也就是说 <code>dependencies[i] != dependencies[j]</code> 。</li>\n\t<li>题目输入的图是个有向无环图。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 84,
|
||||
"likes": 85,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"7.5K\", \"totalAcceptedRaw\": 2852, \"totalSubmissionRaw\": 7475, \"acRate\": \"38.2%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"7.7K\", \"totalAcceptedRaw\": 2939, \"totalSubmissionRaw\": 7718, \"acRate\": \"38.1%\"}",
|
||||
"hints": [
|
||||
"Use backtracking with states (bitmask, degrees) where bitmask represents the set of courses, if the ith bit is 1 then the ith course was taken, otherwise, you can take the ith course. Degrees represent the degree for each course (nodes in the graph).",
|
||||
"Note that you can only take nodes (courses) with degree = 0 and it is optimal at every step in the backtracking take the maximum number of courses limited by k."
|
||||
|
Reference in New Issue
Block a user