{"id":218,"date":"2012-10-27T21:06:00","date_gmt":"2012-10-27T13:06:00","guid":{"rendered":"http:\/\/nike0good.jp1.rpvhost.net\/123"},"modified":"2012-10-27T21:06:00","modified_gmt":"2012-10-27T13:06:00","slug":"cf_237e_letter_select_-_cost_flow","status":"publish","type":"post","link":"https:\/\/nike0good.com\/?p=218","title":{"rendered":"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09"},"content":{"rendered":"<p>\u9898\u76ee\u5927\u610f\uff1a\u6709\u4e00\u5b57\u7b26\u4e32S\uff0c\u4f60\u9700\u8981\u4ecen\u4e2a\u5b57\u7b26\u4e32\u4e2d\u9009\u53d6\u4e00\u4e9b\u6765\u62fc\u51fa\u8fd9\u4e2a\u4e32\uff0c\u7b2ci\u4e2a\u5b57\u7b26\u4e32\u4ee3\u4ef7\u4e3ai\uff0c\u9650\u5236\u53d6P\u6b21\uff0c\u95ee\u6700\u5c0f\u4ee3\u4ef7\uff08\u65e0\u89e3\u8f93\u51fa-1)<\/p>\n<p>\n<\/p>\n<p>\u5efa\u7acb\u8d85\u6e90S=0\uff0c\u8d85\u6c47T=n&#43;26&#43;1&nbsp;<\/p>\n<p>1-n\u7684\u7ed3\u70b9\u4e3a\u5b57\u7b26\u4e32 n&#43;1-n&#43;26\u7684\u7ed3\u70b9\u4e3a\u5b57\u7b26<\/p>\n<p>\u5219\u53ef\u5f97\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<p>\u4eceS\u5411\u5b57\u7b26\u4e32\u8fde\uff08\u6700\u591a\u53ef\u53d6\u6570\u91cf\uff09\uff0c\u8d39\u7528\u4e3ai<\/p>\n<p>\u4ece\u5b57\u7b26\u5411T\u8fde\uff08\u6b32\u53d6\u6570\u91cf\uff09<\/p>\n<p>\u4ece\u5b57\u7b26\u4e32\u5411\u5b57\u7b26\u8fde\uff08\u5b57\u7b26\u4e32\u53ef\u53d6\u8be5\u5b57\u6bcd\u7684\u6570\u91cf\uff09<\/p>\n<p>\u5f97\u5230\u56fe<\/p>\n<p>\u8dd1\u8d39\u7528\u2026\u2026<\/p>\n<p>\n<\/p>\n<p>\uff01\u8d1f\u6570\u7684\u5e03\u5c14&#20540;\u4e3a1.<\/p>\n<p>\n<\/p>\n<p><pre name=\"code\" class=\"cpp\">#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;cstdlib&gt;\n#include&lt;cmath&gt;\n#include&lt;string&gt;\n#include&lt;algorithm&gt;\n#include&lt;functional&gt;\n#include&lt;iostream&gt;\nusing namespace std;\n#define MAXN (200+10)\n#define M26 100\n#define A 96\n#define NONE (2139062143)\nint map[MAXN][MAXN]={0},cost[MAXN][MAXN]={0},stf[M26]={0};\nint start=0,end,n;\nchar s[5000];\n\nint d[MAXN],pre[MAXN],q[MAXN*8];\nbool b[MAXN];\nvoid spfa()\n{\n\tmemset(b,0,sizeof(b));\n\tmemset(d,127,sizeof(d));\n\tmemset(q,0,sizeof(q));\n\tmemset(pre,0,sizeof(pre));\n\n\tint head=1,tail=1;\n\tq[1]=start;b[start]=1;d[start]=0;\n\twhile (head&lt;=tail)\n\t{\n\t\tint now=q[head];\n\t\tfor (int i=0;i&lt;=end;i++)\n\t\tif (map[now][i]&gt;0&amp;&amp;d[now]+cost[now][i]&lt;d[i])\n\t\t{\n\t\t\td[i]=d[now]+cost[now][i];\n\t\t\tpre[i]=now;\n\t\t\tif (!b[i])\n\t\t\t{\n\t\t\t\tq[++tail]=i;\n\t\t\t\tb[i]=1;\n\t\t\t}\n\n\t\t}\n\n\t\tb[now]=0;\n\t\thead++;\n\t}\n\n\n\n}\nvoid hllp()\n{\n\tint totalcost=0;\n\twhile (1)\n\t{\n\t\tspfa();\n\t\tif (d[end]==NONE) break;\n\t\tint flow=NONE,i=end;\n\t\tdo\n\t\t{\n\t\t\tflow=min(flow,map[pre[i]][i]);\n\t\t\ti=pre[i];\n\t\t}while (i!=start);\n\t\ti=end;\n\t\tdo\n\t\t{\n\t\t\ttotalcost+=flow*cost[pre[i]][i];\n\t\t\tmap[pre[i]][i]-=flow;\n\t\t\tmap[i][pre[i]]+=flow;\n\t\t\ti=pre[i];\n\t\t}while (i!=start);\n\n\t}\n\tfor (int i=end-27;i&lt;end;i++)\n\tif (map[i][end])\n\t{\n\t\tcout&lt;&lt;&quot;-1n&quot;;\n\t\treturn;\n\n\t}\n\tcout&lt;&lt;totalcost&lt;&lt;endl;\n}\n\n\n\nint main()\n{\n\/\/\tfreopen(&quot;c.in&quot;,&quot;r&quot;,stdin);\n\tscanf(&quot;%s&quot;,s);\n\tscanf(&quot;%d&quot;,&amp;n);\n\tint len=strlen(s);\n\tfor (int i=0;i&lt;len;i++) stf[s[i]-A]++;\n\tend=n+27;\n\tfor (int i=1;i&lt;=26;i++) map[n+i][end]=stf[i];\n\tfor (int i=1;i&lt;=n;i++)\n\t{\n\t\tscanf(&quot;%s&quot;,s);\n\t\tscanf(&quot;%d&quot;,&amp;map[start][i]);\n\t\tmemset(stf,0,sizeof(stf));\n\t\tfor (int j=0;j&lt;strlen(s);j++) stf[s[j]-A]++;\n\t\tfor (int j=1;j&lt;=26;j++) map[i][n+j]=stf[j];\n\t\tcost[0][i]=i;\n\t\tcost[i][0]=-cost[0][i];\n\t}\n\/*\tfor (int i=0;i&lt;=end;i++)\n\t\tfor (int j=0;j&lt;=end;j++)\n\t\t\tif (map[i][j]) cout&lt;&lt;i&lt;&lt;' '&lt;&lt;j&lt;&lt;' '&lt;&lt;map[i][j]&lt;&lt;endl;\n*\/\thllp();\n\tcout&lt;&lt;'n';\n\/*\tfor (int i=0;i&lt;=end;i++)\n\t\tfor (int j=0;j&lt;=end;j++)\n\t\t\tif (map[i][j]) cout&lt;&lt;i&lt;&lt;' '&lt;&lt;j&lt;&lt;' '&lt;&lt;map[i][j]&lt;&lt;endl;\n*\/\n\treturn 0;\n}<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u5927\u610f\uff1a\u6709\u4e00\u5b57\u7b26\u4e32S\uff0c\u4f60\u9700\u8981\u4ecen\u4e2a\u5b57\u7b26\u4e32\u4e2d\u9009\u53d6\u4e00\u4e9b\u6765\u62fc\u51fa\u8fd9\u4e2a\u4e32\uff0c\u7b2ci\u4e2a\u5b57\u7b26\u4e32\u4ee3\u4ef7\u4e3ai\uff0c\u9650\u5236\u53d6P\u6b21\uff0c\u95ee\u6700\u5c0f\u4ee3\u4ef7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[113],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-defaultcategory","tag-network_flow"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09 - nike0good<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nike0good.com\/?p=218\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09 - nike0good\" \/>\n<meta property=\"og:description\" content=\"\u9898\u76ee\u5927\u610f\uff1a\u6709\u4e00\u5b57\u7b26\u4e32S\uff0c\u4f60\u9700\u8981\u4ecen\u4e2a\u5b57\u7b26\u4e32\u4e2d\u9009\u53d6\u4e00\u4e9b\u6765\u62fc\u51fa\u8fd9\u4e2a\u4e32\uff0c\u7b2ci\u4e2a\u5b57\u7b26\u4e32\u4ee3\u4ef7\u4e3ai\uff0c\u9650\u5236\u53d6P\u6b21\uff0c\u95ee\u6700\u5c0f\u4ee3\u4ef7 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nike0good.com\/?p=218\" \/>\n<meta property=\"og:site_name\" content=\"nike0good\" \/>\n<meta property=\"article:published_time\" content=\"2012-10-27T13:06:00+00:00\" \/>\n<meta name=\"author\" content=\"nike0good\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"nike0good\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=218#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=218\"},\"author\":{\"name\":\"nike0good\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"headline\":\"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09\",\"datePublished\":\"2012-10-27T13:06:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=218\"},\"wordCount\":19,\"commentCount\":0,\"keywords\":[\"\u7f51\u7edc\u6d41\"],\"articleSection\":[\"DefaultCategory\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=218#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=218\",\"url\":\"https:\\\/\\\/nike0good.com\\\/?p=218\",\"name\":\"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09 - nike0good\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\"},\"datePublished\":\"2012-10-27T13:06:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=218#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=218\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=218#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nike0good.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\",\"url\":\"https:\\\/\\\/nike0good.com\\\/\",\"name\":\"nike0good\",\"description\":\"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nike0good.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\",\"name\":\"nike0good\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"caption\":\"nike0good\"},\"sameAs\":[\"https:\\\/\\\/nike0good.com\"],\"url\":\"https:\\\/\\\/nike0good.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09 - nike0good","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nike0good.com\/?p=218","og_locale":"zh_CN","og_type":"article","og_title":"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09 - nike0good","og_description":"\u9898\u76ee\u5927\u610f\uff1a\u6709\u4e00\u5b57\u7b26\u4e32S\uff0c\u4f60\u9700\u8981\u4ecen\u4e2a\u5b57\u7b26\u4e32\u4e2d\u9009\u53d6\u4e00\u4e9b\u6765\u62fc\u51fa\u8fd9\u4e2a\u4e32\uff0c\u7b2ci\u4e2a\u5b57\u7b26\u4e32\u4ee3\u4ef7\u4e3ai\uff0c\u9650\u5236\u53d6P\u6b21\uff0c\u95ee\u6700\u5c0f\u4ee3\u4ef7 [&hellip;]","og_url":"https:\/\/nike0good.com\/?p=218","og_site_name":"nike0good","article_published_time":"2012-10-27T13:06:00+00:00","author":"nike0good","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"nike0good","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nike0good.com\/?p=218#article","isPartOf":{"@id":"https:\/\/nike0good.com\/?p=218"},"author":{"name":"nike0good","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"headline":"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09","datePublished":"2012-10-27T13:06:00+00:00","mainEntityOfPage":{"@id":"https:\/\/nike0good.com\/?p=218"},"wordCount":19,"commentCount":0,"keywords":["\u7f51\u7edc\u6d41"],"articleSection":["DefaultCategory"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nike0good.com\/?p=218#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nike0good.com\/?p=218","url":"https:\/\/nike0good.com\/?p=218","name":"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09 - nike0good","isPartOf":{"@id":"https:\/\/nike0good.com\/#website"},"datePublished":"2012-10-27T13:06:00+00:00","author":{"@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"breadcrumb":{"@id":"https:\/\/nike0good.com\/?p=218#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nike0good.com\/?p=218"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nike0good.com\/?p=218#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nike0good.com\/"},{"@type":"ListItem","position":2,"name":"CF 237E(\u5b57\u6bcd\u9009\u53d6-\u8d39\u7528\u6d41\uff09"}]},{"@type":"WebSite","@id":"https:\/\/nike0good.com\/#website","url":"https:\/\/nike0good.com\/","name":"nike0good","description":"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nike0good.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad","name":"nike0good","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","caption":"nike0good"},"sameAs":["https:\/\/nike0good.com"],"url":"https:\/\/nike0good.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=218"}],"version-history":[{"count":0,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/218\/revisions"}],"wp:attachment":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}