{"id":237,"date":"2017-08-08T07:55:00","date_gmt":"2017-08-08T07:55:00","guid":{"rendered":"https:\/\/www.haoyuan.info\/?p=237"},"modified":"2017-08-05T08:18:09","modified_gmt":"2017-08-05T08:18:09","slug":"%e7%99%be%e5%ba%a6%e4%b9%8b%e6%98%9f2017-1004-%e5%ba%a6%e5%ba%a6%e7%86%8a%e7%9a%84%e5%8d%88%e9%a5%ad%e6%97%b6%e5%85%89-%e5%9b%9e%e6%ba%af","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=237","title":{"rendered":"\u767e\u5ea6\u4e4b\u661f2017 1004 \u5ea6\u5ea6\u718a\u7684\u5348\u996d\u65f6\u5149 \u56de\u6eaf"},"content":{"rendered":"<p>\u8fd9\u9053\u9898\u521a\u5f00\u59cb\u6837\u4f8b\u6539\u4e86\u597d\u591a\u6b21\uff0c\u641e\u5f97\u524d\u4e00\u4e2a\u5c0f\u65f6\u65e0\u4ece\u4e0b\u624b\u3002\u6298\u817e\u4e861002\u65e0\u679c\u4ee5\u540e\u8f6c1004\uff0c\u540e\u6765\u53d1\u73b0\u662f\u4e00\u4e2a\u7b80\u5355\u76840-1\u80cc\u5305\u95ee\u9898\uff0c\u552f\u4e00\u8981\u6ce8\u610f\u7684\u662f\u8bb0\u5f55\u8def\u5f84\uff0c\u5f53\u6709\u591a\u7ec4\u6700\u4f18\u89e3\u7684\u65f6\u5019\u9996\u5148<strong>\u53d6\u6700\u4f18\u89e3\u5e8f\u53f7\u548c\u6700\u5c0f\u7684\u4e00\u7ec4<\/strong>\uff0c\u7136\u540e\u662f<strong>\u53d6\u6700\u4f18\u89e3\u5e8f\u53f7\u6570\u7ec4\u6392\u5217\u5b57\u5178\u6811\u6700\u5c0f\u7684\u4e00\u7ec4<\/strong>\uff0c\u7b80\u5355\u641e\u641e\u5c31\u8fc7\u4e86\u3002<br \/>\n[cc lang=&#8221;c&#8221;]#include<br \/>\n#include<br \/>\n#define in(x) scanf(&#8220;%d&#8221;,&amp;x)<br \/>\n#define inl(x) scanf(&#8220;%lld&#8221;,&amp;x)<br \/>\n#define ins(x) scanf(&#8220;%s&#8221;,x)<br \/>\n#define inf(x) scanf(&#8220;%lf&#8221;,&amp;x)<br \/>\n#define inc(x) scanf(&#8220;%c&#8221;,&amp;x)<br \/>\n#define gc() getchar()<br \/>\n#define out(x) printf(&#8220;%d\\n&#8221;,x)<br \/>\n#define outl(x) printf(&#8220;%lld\\n&#8221;,x)<br \/>\n#define od(x, y) printf(&#8220;%d %d&#8221;,x,y)<br \/>\n#define ms(x) memset(x,0,sizeof(x))<br \/>\n#define msc(x, n) memset(x,n,sizeof(x))<br \/>\n#define cp(x) while(!x.empty())x.pop()<br \/>\n#define rep(i, a, b) for(int i=a;i&lt;b;++i) #define rvep(i, a, b) for(int i=a;i&gt;=b;&#8211;i)<br \/>\n#define elif else if<br \/>\n#define el else<br \/>\n#define wl(x) while(x)<br \/>\n#define sn scanf<br \/>\n#define bl bool<br \/>\n#define mp make_pair<br \/>\n#define pii pair&lt;int,int&gt;<br \/>\n#define rtn return<br \/>\n#define ope operator<br \/>\n#define cst const<br \/>\n#define it int<br \/>\n#define stt struct<br \/>\n#define il inline<br \/>\n#define db double<br \/>\n#define pf printf<br \/>\ntypedef long long ll;<br \/>\ntypedef void vt;<br \/>\nusing namespace std;<br \/>\ncst it INF = 0x3f3f3f3f;<br \/>\nint n, c, bestp, bestw;<br \/>\nint p[10000], w[10000], x[10000], bestx[10000];<br \/>\nint tmp1[10100], tmp2[10100];<br \/>\nvoid Backtrack(int i, int cp, int cw)<br \/>\n{<br \/>\nint j;<br \/>\nif (i &gt; n)<br \/>\n{<br \/>\nif (cp &gt; bestp)<br \/>\n{<br \/>\nbestp = cp;<br \/>\nbestw = cw;<br \/>\nfor (int l = 0; l &lt;= n; l++) bestx[l] = x[l];<br \/>\n}<br \/>\nelse if (cp == bestp)<br \/>\n{<br \/>\nms(tmp1), ms(tmp2);<br \/>\nit cnt = 0;<br \/>\nit sum1, sum2;<br \/>\nsum1 = sum2 = 0;<br \/>\nrep(l, 1, n + 1)<br \/>\n{<br \/>\nif (x[l])<br \/>\n{<br \/>\ntmp1[cnt++] = l;<br \/>\nsum1 += l;<br \/>\n}<br \/>\n}<br \/>\ncnt = 0;<br \/>\nrep(l, 1, n + 1)<br \/>\n{<br \/>\nif (bestx[l])<br \/>\n{<br \/>\ntmp2[cnt++] = l;<br \/>\nsum2 += l;<br \/>\n}<br \/>\n}<br \/>\nif (sum1 &lt; sum2)<br \/>\n{<br \/>\nbestp = cp;<br \/>\nbestw = cw;<br \/>\nfor (int l = 0; l &lt;= n; l++) bestx[l] = x[l]; return; } if (sum1 &gt; sum2)<br \/>\n{<br \/>\nreturn;<br \/>\n}<br \/>\nbool f = false;<br \/>\nfor (int l = 0;; ++l)<br \/>\n{<br \/>\nif (tmp1[l] == 0 &amp;&amp; tmp2[l] != 0)<br \/>\n{<br \/>\nf = true;<br \/>\nbreak;<br \/>\n}<br \/>\nif (tmp1[l] == tmp2[l])continue;<br \/>\nif (tmp1[l] != 0 &amp;&amp; tmp2[l] == 0)break;<br \/>\nif (tmp1[l] &lt; tmp2[l]) { f = true; break; } if (tmp1[l] &gt; tmp2[l])continue;<br \/>\n}<br \/>\nif (f)<br \/>\n{<br \/>\nbestp = cp;<br \/>\nbestw = cw;<br \/>\nfor (int l = 0; l &lt;= n; l++) bestx[l] = x[l];<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nfor (j = 0; j &lt;= 1; j++)<br \/>\n{<br \/>\nx[i] = j;<br \/>\nif (cw + x[i] * w[i] &lt;= c)<br \/>\n{<br \/>\ncw += w[i] * x[i];<br \/>\ncp += p[i] * x[i];<br \/>\nBacktrack(i + 1, cp, cw);<br \/>\ncw -= w[i] * x[i];<br \/>\ncp -= p[i] * x[i];<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n#ifndef ONLINE_JUDGE<br \/>\nfreopen(&#8220;1001.in&#8221;, &#8220;r&#8221;, stdin);<br \/>\nfreopen(&#8220;test.out&#8221;, &#8220;w&#8221;, stdout);<br \/>\n#endif<br \/>\nit T;<br \/>\nin(T);<br \/>\nrep(kase, 1, T + 1)<br \/>\n{<br \/>\nms(p), ms(w), ms(x);<br \/>\nms(bestx);<br \/>\nbestp = 0;<br \/>\nbestw = 0;<br \/>\nin(c), in(n);<br \/>\nrep(i, 1, n + 1)<br \/>\n{<br \/>\nin(p[i]);<br \/>\nin(w[i]);<br \/>\n};<br \/>\nBacktrack(1, 0, 0);<br \/>\nprintf(&#8220;Case #%d:\\n&#8221;, kase);<br \/>\nprintf(&#8220;%d %d\\n&#8221;, bestp, bestw);<br \/>\nbool f = false;<br \/>\nrep(i, 1, n + 1)<br \/>\n{<br \/>\nif (f)<br \/>\n{<br \/>\nif (bestx[i])printf(&#8221; %d&#8221;, i);<br \/>\n}<br \/>\nel<br \/>\n{<br \/>\nif (bestx[i])<br \/>\n{<br \/>\nf = true;<br \/>\nprintf(&#8220;%d&#8221;, i);<br \/>\n}<br \/>\n}<br \/>\nif (i == n &amp;&amp; f)puts(&#8220;&#8221;);<br \/>\n}<br \/>\n}<br \/>\nreturn 0;<br \/>\n}<br \/>\n[\/cc]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u9053\u9898\u521a\u5f00\u59cb\u6837\u4f8b\u6539\u4e86\u597d\u591a\u6b21\uff0c\u641e\u5f97\u524d\u4e00\u4e2a\u5c0f\u65f6\u65e0\u4ece\u4e0b\u624b\u3002\u6298\u817e\u4e861002\u65e0\u679c\u4ee5\u540e\u8f6c1004\uff0c\u540e\u6765\u53d1\u73b0\u662f\u4e00\u4e2a\u7b80\u5355\u76840- [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-1"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-3P","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=237"}],"version-history":[{"count":3,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/237\/revisions\/240"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}