{"id":169763,"date":"2020-10-17T10:03:55","date_gmt":"2020-10-17T02:03:55","guid":{"rendered":"http:\/\/4563.org\/?p=169763"},"modified":"2020-10-17T10:03:55","modified_gmt":"2020-10-17T02:03:55","slug":"linkedin-%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e6%88%bf%e5%b1%8b%e6%9f%93%e8%89%b2%ef%bc%88%e5%8a%a8%e8%a7%84%e6%80%9d%e8%b7%af%ef%bc%89","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=169763","title":{"rendered":"LinkedIn \u9762\u8bd5\u9898\uff1a\u623f\u5c4b\u67d3\u8272\uff08\u52a8\u89c4\u601d\u8def\uff09"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  LinkedIn \u9762\u8bd5\u9898\uff1a\u623f\u5c4b\u67d3\u8272\uff08\u52a8\u89c4\u601d\u8def\uff09               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u8fd9\u91cc\u6709 n \u4e2a\u623f\u5b50\u5728\u4e00\u5217\u76f4\u7ebf\u4e0a\uff0c\u73b0\u5728\u6211\u4eec\u9700\u8981\u7ed9\u623f\u5c4b\u67d3\u8272\uff0c\u5206\u522b\u6709\u7ea2\u8272\u84dd\u8272\u548c\u7eff\u8272\u3002\u6bcf\u4e2a\u623f\u5c4b\u67d3\u4e0d\u540c\u7684\u989c\u8272\u8d39\u7528\u4e5f\u4e0d\u540c\uff0c\u4f60\u9700\u8981\u8bbe\u8ba1\u4e00\u79cd\u67d3\u8272\u65b9\u6848\u4f7f\u5f97\u76f8\u90bb\u7684\u623f\u5c4b\u989c\u8272\u4e0d\u540c\uff0c\u5e76\u4e14\u8d39\u7528\u6700\u5c0f\uff0c\u8fd4\u56de\u6700\u5c0f\u7684\u8d39\u7528\u3002 \u8d39\u7528\u901a\u8fc7\u4e00\u4e2a nx3 \u7684\u77e9\u9635\u7ed9\u51fa\uff0c\u6bd4\u5982 cost[0][0]\u8868\u793a\u623f\u5c4b 0 \u67d3\u7ea2\u8272\u7684\u8d39\u7528\uff0ccost[1][2]\u8868\u793a\u623f\u5c4b 1 \u67d3\u7eff\u8272\u7684\u8d39\u7528\u3002<\/p>\n<p>\u5728\u7ebf\u8bc4\u6d4b\u5730\u5740<\/p>\n<h2>\u6837\u4f8b 1:<\/h2>\n<pre><code>\u8f93\u5165: [[14,2,11],[11,14,5],[14,3,10]] \u8f93\u51fa: 10 \u89e3\u91ca: \u7b2c\u4e00\u4e2a\u5c4b\u5b50\u67d3\u84dd\u8272\uff0c\u7b2c\u4e8c\u4e2a\u67d3\u7eff\u8272\uff0c\u7b2c\u4e09\u4e2a\u67d3\u84dd\u8272\uff0c\u6700\u5c0f\u82b1\u8d39\uff1a2 + 5 + 3 = 10. <\/code><\/pre>\n<h2>\u6837\u4f8b 2:<\/h2>\n<pre><code>\u8f93\u5165: [[1,2,3],[1,4,6]] \u8f93\u51fa: 3 <\/code><\/pre>\n<h2>\u7b97\u6cd5\uff1a\u52a8\u6001\u89c4\u5212(dp)<\/h2>\n<h2>\u7b97\u6cd5\u601d\u8def<\/h2>\n<ul>\n<li>dp[i][j]\u8868\u793a\u7b2c i \u5e62\u623f\u5b50\u6d82 j \u7684\u989c\u8272\u6700\u5c0f\u7684\u82b1\u8d39\u603b\u548c\uff0c\u5373\u4ece\u524d\u4e00\u5e62\u623f\u5b50\u7684\u72b6\u6001 dp[i-1][k] (k != j)\u4e2d\u9009\u4e00\u4e2a\u4e0d\u540c\u989c\u8272\u4e14\u6700\u5c0f\u7684\u518d\u52a0\u4e0a\u7ed9\u7b2c i \u5e62\u623f\u5b50\u6d82 j \u989c\u8272\u7684 costs \u3002<\/li>\n<\/ul>\n<h2>\u4ee3\u7801\u601d\u8def<\/h2>\n<ol>\n<li>\u521d\u59cb\u5316\u72b6\u6001 dp[0][i]=costs[0][i]<\/li>\n<li>\u4ece\u5de6\u5f80\u53f3\u904d\u5386\u6bcf\u4e00\u5e62\u623f\u5b50\uff0c\u8ba1\u7b97\u5230\u8be5\u5e62\u623f\u5b50\u6d82\u6bcf\u79cd\u989c\u8272\u7684\u6700\u5c0f\u82b1\u8d39\uff0c\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u662f dp[i][j] = min{dp[i-1][k] +costs[i][j]} (k != j)<\/li>\n<li>\u7b54\u6848\u4e3a\u5230\u6700\u540e\u4e00\u5e62\u623f\u5b50\u6d82\u6bcf\u79cd\u989c\u8272\u82b1\u8d39\u4e2d\u7684\u6700\u5c0f\u503c\uff0c\u5373 min(dp[n-1][k]),k=0,1,2<\/li>\n<\/ol>\n<h2>\u590d\u6742\u5ea6\u5206\u6790<\/h2>\n<p>N \u8868\u793a\u623f\u5b50\u7684\u5e62\u6570\uff0c\u5373 costs \u6570\u7ec4\u957f\u5ea6<\/p>\n<ul>\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(1)<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(N)<\/li>\n<\/ul>\n<h2>\u4f18\u5316<\/h2>\n<ul>\n<li>\u6eda\u52a8\u5b58\u50a8\u72b6\u6001\uff0c\u53ef\u4ee5\u5c06\u7a7a\u95f4\u590d\u6742\u5ea6\u4ece O(N)\u4f18\u5316\u5230 O(1)\u3002<\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code>public class Solution {      \/**      * @param costs: n x 3 cost matrix      * @return: An integer, the minimum cost to paint all houses      *\/      public int minCost(int[][] costs) {         int n = costs.length;         if (n == 0) {             return 0;         }          \/\/dp[i][j]\u8868\u793a\u7b2c i \u5e62\u623f\u5b50\u6d82 j \u7684\u989c\u8272\u6700\u5c0f\u7684\u603b\u548c         \/\/\u521d\u59cb\u5316\u72b6\u6001 dp[0][i]=costs[0][i]          int[][] dp = new int[2][3];          for (int i= 0; i &lt; 3; i++) {             dp[0][i] = costs[0][i];         }          for (int i = 1; i &lt; n; i++) {             for (int j = 0; j &lt; 3; j++) {                 dp[i&amp;1][j] = Integer.MAX_VALUE;                 for (int k = 0; k &lt; 3; k++) {                     if (k != j) {                         dp[i&amp;1][j] = Math.min(dp[i&amp;1][j], dp[i&amp;1^1][k] + costs[i][j]);                     }                 }             }         }         return Math.min(dp[n&amp;1^1][0], Math.min(dp[n&amp;1^1][1], dp[n&amp;1^1][2]) );     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>LinkedIn \u9762\u8bd5\u9898\uff1a\u623f\u5c4b\u67d3\u8272&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\/169763"}],"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=169763"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/169763\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169763"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}