{"id":384524,"date":"2021-03-11T06:27:18","date_gmt":"2021-03-10T22:27:18","guid":{"rendered":"http:\/\/4563.org\/?p=384524"},"modified":"2021-03-11T06:27:18","modified_gmt":"2021-03-10T22:27:18","slug":"%e7%bd%91%e6%98%93%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e6%9c%80%e5%a4%a7%e7%ba%bf%e6%ae%b5%e8%a6%86%e7%9b%96","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=384524","title":{"rendered":"\u7f51\u6613\u9762\u8bd5\u9898\uff1a\u6700\u5927\u7ebf\u6bb5\u8986\u76d6"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u7f51\u6613\u9762\u8bd5\u9898\uff1a\u6700\u5927\u7ebf\u6bb5\u8986\u76d6               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h3>\u63cf\u8ff0<\/h3>\n<p>\u5728\u4e00\u4e2a\u6570\u8f74\u4e0a\u7ed9\u51fa n \u4e2a\u7ebf\u6bb5\uff0c\u95ee\u9009\u62e9\u4e0d\u8d85\u8fc7 k \u4e2a\u7ebf\u6bb5\uff0c\u4f7f\u5f97\u8fd9 k \u4e2a\u7ebf\u6bb5\u8986\u76d6\u7684\u6570\u6700\u591a\u3002<\/p>\n<p>\u5728\u7ebf\u8bc4\u6d4b\u5730\u5740<\/p>\n<h3>\u6837\u4f8b 1<\/h3>\n<pre><code>Input: [(1,2),(2,3),(3,4)] 2 Output: 4 Explanation: Select the line segment (1,2), (3,4), which can cover the 4 numbers of 1,2,3,4. <\/code><\/pre>\n<h3>\u6837\u4f8b 2<\/h3>\n<pre><code>Input: [(1,2),(2,3),(1,7)] 2 Output: 7 Explanation: Selecting the line segment (1,7) ,which can cover the 7 numbers of 1,2,3,4,5,6,7. <\/code><\/pre>\n<h3>\u9898\u89e3<\/h3>\n<p>dp[i][j]dp[i][j]\u8868\u793a\u7528 jj \u4e2a\u7ebf\u6bb5\u8986\u76d6\u524d ii \u4e2a\u6570\u7684\u6700\u4f18\u7b54\u6848\u3002\u5148\u5c06\u6240\u6709\u7ebf\u6bb5\u6309\u7167\u5de6\u7aef\u70b9\u6392\u5e8f\uff0c\u5bf9\u4e8e\u5de6\u7aef\u70b9\u76f8\u540c\u7684\u7ebf\u6bb5\uff0c\u53d6\u6700\u957f\u7684\u62ff\u6765\u8f6c\u79fb\u3002 \u5219\u6709\uff1adp[i+1][j]=max(dp[i][j],dp[i+1][j])dp[i+1][j]=max(dp[i][j],dp[i+1][j]) dp[i+num][j+1]=max(dp[i][j]+num,dp[i+num][j+1])dp[i+num][j+1]=max(dp[i][j]+num,dp[i+num][j+1])(num \u4e3a\u7ebf\u6bb5\u957f\u5ea6)<\/p>\n<pre><code>\/**  * Definition of Interval:  * public classs Interval {  *     int start, end;  *     Interval(int start, int end) {  *         this.start = start;  *         this.end = end;  *     }  * }  *\/  public class Solution {     \/**      * @param intervals: The intervals      * @param k: The k      * @return: The answer      *\/          class Cmp implements Comparator&lt;Interval&gt;{        @Override        public int compare(Interval a, Interval b){             if(a.start == b.start) {                 return a.end - b.end;             }             return a.start - b.start;         }     }           public int maximumLineCoverage(List&lt;Interval&gt; intervals, int k) {         \/\/ Write your code here         Collections.sort(intervals, new Cmp());         int index = 0;         int num = 0;         int maxnum = 0;         int[][] dp = new int[2005][2005];         for (int i = 0; i &lt; intervals.size(); i++) {             maxnum = Math.max(intervals.get(i).end, maxnum);         }         for (int i = 0; i &lt; maxnum; i++) {             while (index &lt; intervals.size() &amp;&amp; intervals.get(index).start == i + 1) {                 num = Math.max(num, intervals.get(index).end - intervals.get(index).start + 1);                 index++;             }             for (int j = 0; j &lt;= k; j++) {                 dp[i + 1][j] = Math.max(dp[i][j], dp[i + 1][j]);\/\/\u4e0d\u53d6                 if (i + num &lt;= maxnum) {                     dp[i + num][j + 1] = Math.max(dp[i][j] + num, dp[i + num][j + 1]);\/\/\u53d6                 }             }             if (num &gt; 0) {\/\/i \u52a0\u4e86 1\uff0c\u6240\u4ee5\u7ebf\u6bb5\u957f\u5ea6\u51cf 1                 num--;             }         }         return dp[maxnum][k];     } } <\/code><\/pre>\n<p>\u66f4\u591a\u9898\u89e3\u53c2\u8003<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5362145\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Olament <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             int[][] dp = new int[2005][2005]; \/\/ ???                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5362146\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rocbomb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u54ea\u91cc\u8f6c\u8f7d\u7684\uff1f<br \/>\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u90fd\u9ecf\u5230\u4e00\u8d77\u4e86<br \/> dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])<br \/> dp[i + num][j + 1] = max(dp[i][j] + num, dp[i + num][j + 1])                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u6613\u9762\u8bd5\u9898\uff1a\u6700\u5927\u7ebf\u6bb5\u8986\u76d6 \u8cc7\u6df1\u5927\u4f6c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/384524"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=384524"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/384524\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=384524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=384524"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=384524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}