{"id":555,"date":"2020-05-19T16:11:20","date_gmt":"2020-05-19T08:11:20","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=555"},"modified":"2020-05-19T18:08:03","modified_gmt":"2020-05-19T10:08:03","slug":"%e6%a6%82%e7%8e%87dp","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/05\/19\/%e6%a6%82%e7%8e%87dp\/","title":{"rendered":"\u6982\u7387dp"},"content":{"rendered":"<h4>\u6982\u7387dp<\/h4>\n<p>\u6982\u7387\u503c\u4e3a\u4e00\u4e2a\u4e0d\u53ef\u7ea6\u5206\u6570<code class=\"katex-inline\">\\frac{a}{b}<\/code>\u5bf9\u6a21\u6570mod\u53d6\u6a21\u7684\u542b\u4e49\u4e3a\uff1a\u5b58\u5728q\u4f7f\u5f97<code class=\"katex-inline\">b \\times q\\%mod=a<\/code>\uff0cq\u5c31\u662f<code class=\"katex-inline\">\\frac{a}{b}<\/code>\u5bf9mod\u53d6\u6a21\u7684\u503c\u3002\u8981\u628a\u4e00\u4e2a\u5206\u5f0f\u6982\u7387\u8f6c\u5316\u6210\u6a21\u503c\u65f6\uff0c\u8981\u7528\u5230\u6269\u5c55\u6b27\u51e0\u91cc\u5f97\uff1b\u82e5\u9898\u76ee\u4e5f\u76f4\u63a5\u7ed9\u51fa\u6a21\u503c\uff0c\u5219\u4e0d\u9700\u8981\u3002<br \/>\n\u6982\u7387\u4e3a0\u662f\uff0cq\u4e3a0\uff1b\u6982\u7387\u4e3a1\u662f\uff0cq\u4e3a1\u3002<br \/>\n\u90a3\u4e48\u5f53\u67d0\u4e2a\u4e8b\u4ef6\u53d1\u751f\u7684\u6982\u7387\u4e3aq\u65f6\uff0c\u5b83\u4e0d\u53d1\u751f\u7684\u6982\u7387\u5c31\u662f1-q\uff0c\u6839\u636e(q+1-q)=1\uff0c\u53ef\u4ee5\u5f97\u51fa<code class=\"katex-inline\">(q+1-q)\\%mod=1\uff0c1-q=mod+1-q<\/code>\u3002<br \/>\n\u4e24\u4e2a\u5206\u5f0f\u6982\u7387\u76f8\u4e58\u65f6\uff0c\u76f4\u63a5\u4e58\u5c31\u597d\u4e86\uff1b\u6a21\u503c\u610f\u4e49\u4e0b\u7684\u6982\u7387\u4e5f\u662f\u76f4\u63a5\u4e58\uff0c\u4e0d\u8fc7\u4e58\u5b8c\u4e4b\u540e\u8981\u5bf9mod\u518d\u53d6\u4e00\u6b21\u6a21\u3002<br \/>\n<a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/3003\/C\">\u7b97\u6982\u7387<\/a><br \/>\n\u7ed9\u51fan\u9053\u9898\u6a21\u503c\u610f\u4e49\u4e0b\u505a\u5bf9\u7684\u6982\u7387\uff0c\u6c42\u8fd9n\u9053\u9898\u4e2d\uff0c\u603b\u5171\u4f5c\u5bf90\uff0c1\uff0c...n\u5230\u9898\u7684\u6982\u7387\u3002<br \/>\ndp[i][j]\u8868\u793a\u524di\u9053\u9898\u4e2d\uff0c\u505a\u5bf9j\u9053\u7684\u6982\u7387\u3002<br \/>\ndp[i][j] = (dp[i-1][j]*(mod+1-p[i])+dp[i-1][j-1]*p[i])%mod<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\ntypedef long long ll;\nconst ll mod = 1e9+7;\nconst int maxn = 2e3+5;\nll ans[maxn][maxn];\nll n,p[maxn];\nint main(){\n    cin &gt;&gt; n;\n    for (int i=1;i&lt;=n;i++)\n        cin &gt;&gt; p[i];\n    ans[0][0] = 1;\n    for (int i=1;i&lt;=n;i++){\n        ans[i][0] = ans[i-1][0]*(mod+1-p[i])%mod;\n        for (int j=1;j&lt;=i;j++){\n            ans[i][j] = (ans[i-1][j]*(mod+1-p[i])+ans[i-1][j-1]*p[i])%mod;\n        }\n    }\n    for (int i=0;i&lt;=n;i++){\n        printf(&quot;%lld&quot;,ans[n][i]);\n        if (i!=n)   printf(&quot; &quot;);\n    }\n    return 0;\n}<\/code><\/pre>\n<h4><a href=\"https:\/\/ac.nowcoder.com\/acm\/problem\/14734\">NC14734 \u6bd4\u8d5b<\/a><\/h4>\n<p>\u6982\u7387\u4ee5\u5c0f\u6570\u5f62\u5f0f\u7ed9\u51fa\u3002<br \/>\n\u5bf9\u4e8e\u6bcf\u9053\u9898\uff0c\u76f4\u63a5\u6c42\u901a\u8fc7\u7684\u6982\u7387\u662f\u6bd4\u8f83\u96be\u6c42\u7684\uff1b\u53ef\u4ee5\u5bb9\u6613\u6c42\u51fa\u4e0d\u901a\u8fc7\u8fd9\u9053\u9898\u7684\u6982\u7387\uff1ad[i] = (1-a[i])*(1-b[i])*(1-c[i])<br \/>\n\u90a3\u4e48\u901a\u8fc7\u8fd9\u9053\u9898\u7684\u6982\u7387\u5c31\u662f 1-d[i]<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\ndouble a[20], b[20], c[20], d[20], dp[20][20];\nint main(){\n    for (int i=1;i&lt;=12;i++)    cin &gt;&gt; a[i];\n    for (int i=1;i&lt;=12;i++)    cin &gt;&gt; b[i];\n    for (int i=1;i&lt;=12;i++)    cin &gt;&gt; c[i];\n    for (int i=1;i&lt;=12;i++)\n        d[i] = (1-a[i])*(1-b[i])*(1-c[i]);\n    dp[0][0] = 1;\n    for (int i=1;i&lt;=12;i++){\n        dp[i][0] = dp[i-1][0]*d[i];\n        for (int j=1;j&lt;=i;j++){\n            dp[i][j] = dp[i-1][j]*d[i] + dp[i-1][j-1]*(1-d[i]);\n        }\n    }\n    for (int i=0;i&lt;=12;i++)\n        printf (&quot;%.6lf\\n&quot;, dp[12][i]);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u7387dp \u6982\u7387\u503c\u4e3a\u4e00\u4e2a\u4e0d\u53ef\u7ea6\u5206\u6570\\frac{a}{b}\u5bf9\u6a21\u6570mod\u53d6\u6a21\u7684\u542b\u4e49\u4e3a\uff1a\u5b58\u5728q\u4f7f\u5f97b \\ti [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/555"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=555"}],"version-history":[{"count":10,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/555\/revisions"}],"predecessor-version":[{"id":558,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/555\/revisions\/558"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=555"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}