{"id":94,"date":"2025-01-11T23:24:55","date_gmt":"2025-01-11T15:24:55","guid":{"rendered":"http:\/\/150.230.63.147\/blog\/?p=94"},"modified":"2025-01-11T23:24:55","modified_gmt":"2025-01-11T15:24:55","slug":"d-yet-another-problem-on-a-subsequence-%e8%a7%a3%e6%9e%90dp","status":"publish","type":"post","link":"https:\/\/blog.seekrealthing.net\/blog\/?p=94","title":{"rendered":"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP)"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><h1>Codeforce 1000 D. Yet Another Problem On a Subsequence \u89e3\u6790(DP)<\/h1>\n<p>\u4eca\u5929\u6211\u5011\u4f86\u770b\u770bCF1000D<br>\n<a href=\"https:\/\/codeforces.com\/problemset\/problem\/1000\/D\">\u984c\u76ee\u9023\u7d50<\/a><\/p>\n<blockquote>\n<p><strong>\u984c\u76ee<\/strong><br>\n\u7565\uff0c\u8acb\u76f4\u63a5\u770b\u539f\u984c<\/p>\n<\/blockquote>\n<h3>\u524d\u8a00<\/h3>\n<p>\u9019\u984c\u63d0\u4f9b\u4e86\u6211\u4e00\u7a2e\u5be6\u7528\u7684\u7b97$C_m^n$\u7684\u65b9\u6cd5<\/p>\n<h3>\u60f3\u6cd5<\/h3>\n<p>\u8003\u616e$dp[i]$\u70ba\u8003\u616e\u5230$i$\u4f4d\u7f6e\u70ba\u6b62\u7684\u6240\u4ee5$subsequence$\u6578\u91cf$+1$(\u4e00\u500b\u90fd\u4e0d\u9078)\uff0c\u89e3\u7b54\u5c31\u662f$dp[n]-1$\u3002<br>\n\u6bcf\u6b21\u65b0\u8003\u616e\u4e00\u500b$dp[i]$\u6642\uff0c$dp[i]$\u7531\u4e0d\u5305\u542b$a[i]$($a$\u662f\u539f\u6578\u5217)\u7684$subsequence$\u6578\u91cf\u52a0\u4e0a\u5305\u542b$a[i]$\u7684$subsequence$\u6578\u91cf\u3002\u800c\u8003\u616e\u5305\u542b$a[i]$\u7684\u6578\u91cf\u6642\uff0c\u6211\u5011\u53ea\u9700\u8981\u5f80\u524d\u627e\u6700\u5f8c\u4e00\u500b$subarray$\u7684\u8d77\u9ede($a[j]&gt;0$)\uff0c\u63a5\u8457\u4f7f\u7528$C_m^n$\u627e\u51fa\u6700\u5f8c\u7684$subarray$\u6709\u5e7e\u7a2e\u53ef\u80fd\u5c31\u597d\u3002<\/p>\n<p>\u91cd\u9ede\u5728\u65bc\u8981\u5982\u4f55\u8a08\u7b97$C_m^n$\uff0c\u6578\u5b57\u592a\u5bb9\u6613\u7206\u6389\u4e86\u3002\u9019\u6642\u5019\u6211\u5011\u8981\u5229\u7528$C_m^n=C_m^{n-1}+C_{m-1}^{n-1}$\uff0c\u9019\u6a23\u5c31\u4e0d\u6703\u7206\u6389\u4e86\uff0c\u4e26\u4e14\u8981\u7279\u5225\u4ee4$C_0^0=1$\uff0c\u56e0\u70ba\u6211\u5011\u4e4b\u5f8c\u8a08\u7b97$dp$\u6642\u6703\u7528\u5230\u3002<\/p>\n<p>\u8f49\u79fb\u5f0f$:dp[i]=dp[i-1]+\\sum\\limits_{j=1}^{i-1}dp[j-1]\\times C_{a[j]-1}^{i-j-1}$<\/p>\n<p>\u6ce8\u610f:\u6211\u5011\u4ee4$dp[0]=1$\u4ee5\u65b9\u4fbf\u8a08\u7b97\u3002\u800c\u6578\u5217\u6a19\u865f\u662f\u5f9e$1$\u958b\u59cb\u3002<\/p>\n<h3>\u7a0b\u5f0f\u78bc:<\/h3>\n<pre><code class=\"language-cpp=\">inline int pmod(int x, int d){int m = x%d;return m+((m&gt;&gt;31)&amp;d);}  \nconst int _n=1010;  \nint t,n,a[_n],dp[_n],C[_n][_n];  \nmain(void) {cin.tie(0);ios_base::sync_with_stdio(0);  \n  cin&gt;&gt;n;rep(i,1,n+1)cin&gt;&gt;a[i];  \n  rep(i,1,n+1){  \n    C[i][0]=C[i][i]=1;  \n    rep(j,1,i)C[i][j]=(1ll*C[i-1][j]+1ll*C[i-1][j-1])%mod;  \n  }C[0][0]=1;  \n  dp[0]=dp[1]=1;  \n  rep(i,2,n+1){  \n    dp[i]=dp[i-1];  \n    per(j,1,i)  \n      if(a[j]&gt;0 and a[j]&lt;=i-j)dp[i]=(dp[i]+(1ll*dp[j-1]*C[i-j-1][a[j]-1]))%mod;  \n  }  \n  cout&lt;&lt;pmod(dp[n]-1,mod)&lt;&lt;'\\n';  \n  return 0;  \n}  \n<\/code><\/pre>\n<p>\u6a19\u982d\u3001\u6a21\u677f\u8acb\u9edeSubmission\u770b<br>\n<a href=\"https:\/\/codeforces.com\/contest\/1000\/submission\/92117053\">Submission<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[3],"tags":[10,4,9],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-ojcode","tag-codeforce","tag-dp","tag-ojcode"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>D. Yet Another Problem On a Subsequence \u89e3\u6790(DP) - Logic Formatting<\/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:\/\/blog.seekrealthing.net\/blog\/?p=94\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP) - Logic Formatting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.seekrealthing.net\/blog\/?p=94\" \/>\n<meta property=\"og:site_name\" content=\"Logic Formatting\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-11T15:24:55+00:00\" \/>\n<meta name=\"author\" content=\"jeff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005:\" \/>\n\t<meta name=\"twitter:data1\" content=\"jeff\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u4f30\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94\"},\"author\":{\"name\":\"jeff\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/person\/233e80a0fee3d4706f067f2e88c0b454\"},\"headline\":\"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP)\",\"datePublished\":\"2025-01-11T15:24:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94\"},\"wordCount\":83,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#organization\"},\"keywords\":[\"codeforce\",\"DP\",\"ojcode\"],\"articleSection\":[\"ojcode\"],\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.seekrealthing.net\/blog\/?p=94#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94\",\"url\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94\",\"name\":\"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP) - Logic Formatting\",\"isPartOf\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#website\"},\"datePublished\":\"2025-01-11T15:24:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.seekrealthing.net\/blog\/?p=94\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/?p=94#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9801\",\"item\":\"https:\/\/blog.seekrealthing.net\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#website\",\"url\":\"https:\/\/blog.seekrealthing.net\/blog\/\",\"name\":\"Logic Formatting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.seekrealthing.net\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#organization\",\"name\":\"Logic Formatting\",\"url\":\"https:\/\/blog.seekrealthing.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.seekrealthing.net\/blog\/wp-content\/uploads\/2025\/02\/android-chrome-512x512-1.png\",\"contentUrl\":\"https:\/\/blog.seekrealthing.net\/blog\/wp-content\/uploads\/2025\/02\/android-chrome-512x512-1.png\",\"width\":512,\"height\":512,\"caption\":\"Logic Formatting\"},\"image\":{\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/person\/233e80a0fee3d4706f067f2e88c0b454\",\"name\":\"jeff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f9b571b28c252728386f0002b35d9cb9a9028f740b0f9ca5ad678e7eb21c4857?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f9b571b28c252728386f0002b35d9cb9a9028f740b0f9ca5ad678e7eb21c4857?s=96&d=mm&r=g\",\"caption\":\"jeff\"},\"sameAs\":[\"http:\/\/150.230.63.147\/blog\"],\"url\":\"https:\/\/blog.seekrealthing.net\/blog\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP) - Logic Formatting","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:\/\/blog.seekrealthing.net\/blog\/?p=94","og_locale":"zh_TW","og_type":"article","og_title":"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP) - Logic Formatting","og_url":"https:\/\/blog.seekrealthing.net\/blog\/?p=94","og_site_name":"Logic Formatting","article_published_time":"2025-01-11T15:24:55+00:00","author":"jeff","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005:":"jeff","\u9810\u4f30\u95b1\u8b80\u6642\u9593":"1 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.seekrealthing.net\/blog\/?p=94#article","isPartOf":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/?p=94"},"author":{"name":"jeff","@id":"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/person\/233e80a0fee3d4706f067f2e88c0b454"},"headline":"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP)","datePublished":"2025-01-11T15:24:55+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/?p=94"},"wordCount":83,"commentCount":0,"publisher":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/#organization"},"keywords":["codeforce","DP","ojcode"],"articleSection":["ojcode"],"inLanguage":"zh-TW","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.seekrealthing.net\/blog\/?p=94#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.seekrealthing.net\/blog\/?p=94","url":"https:\/\/blog.seekrealthing.net\/blog\/?p=94","name":"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP) - Logic Formatting","isPartOf":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/#website"},"datePublished":"2025-01-11T15:24:55+00:00","breadcrumb":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/?p=94#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.seekrealthing.net\/blog\/?p=94"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.seekrealthing.net\/blog\/?p=94#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9801","item":"https:\/\/blog.seekrealthing.net\/blog"},{"@type":"ListItem","position":2,"name":"D. Yet Another Problem On a Subsequence \u89e3\u6790(DP)"}]},{"@type":"WebSite","@id":"https:\/\/blog.seekrealthing.net\/blog\/#website","url":"https:\/\/blog.seekrealthing.net\/blog\/","name":"Logic Formatting","description":"","publisher":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.seekrealthing.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-TW"},{"@type":"Organization","@id":"https:\/\/blog.seekrealthing.net\/blog\/#organization","name":"Logic Formatting","url":"https:\/\/blog.seekrealthing.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/blog.seekrealthing.net\/blog\/wp-content\/uploads\/2025\/02\/android-chrome-512x512-1.png","contentUrl":"https:\/\/blog.seekrealthing.net\/blog\/wp-content\/uploads\/2025\/02\/android-chrome-512x512-1.png","width":512,"height":512,"caption":"Logic Formatting"},"image":{"@id":"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/person\/233e80a0fee3d4706f067f2e88c0b454","name":"jeff","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/blog.seekrealthing.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f9b571b28c252728386f0002b35d9cb9a9028f740b0f9ca5ad678e7eb21c4857?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f9b571b28c252728386f0002b35d9cb9a9028f740b0f9ca5ad678e7eb21c4857?s=96&d=mm&r=g","caption":"jeff"},"sameAs":["http:\/\/150.230.63.147\/blog"],"url":"https:\/\/blog.seekrealthing.net\/blog\/?author=1"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":1,"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":95,"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/95"}],"wp:attachment":[{"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.seekrealthing.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}