{"id":9108,"date":"2024-05-13T13:01:01","date_gmt":"2024-05-13T05:01:01","guid":{"rendered":""},"modified":"2024-05-13T13:01:01","modified_gmt":"2024-05-13T05:01:01","slug":"M\u4e2a\u82f9\u679c\u653eN\u4e2a\u7bee\u5b50\uff0c\u7bee\u5b50\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u6709\u591a\u5c11\u79cd\u653e\u6cd5\uff1f","status":"publish","type":"post","link":"https:\/\/mushiming.com\/9108.html","title":{"rendered":"M\u4e2a\u82f9\u679c\u653eN\u4e2a\u7bee\u5b50\uff0c\u7bee\u5b50\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u6709\u591a\u5c11\u79cd\u653e\u6cd5\uff1f"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u95ee\u9898<\/strong>\uff1a
M\u4e2a\u82f9\u679c\u653eN\u4e2a\u7bee\u5b50\uff0c\u7bee\u5b50\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u6709\u591a\u5c11\u79cd\u653e\u6cd5\uff1f<\/p>\n

\u5206\u6790<\/strong>\uff1a
\u5f53m=0,\u6216\u8005n=1\u65f6\u5019\uff0c\u53ea\u6709\u4e00\u79cd\u653e\u6cd5\uff0c\u7bee\u5b50\u53ea\u6709\u4e00\u4e2a\uff0c
\u5f53n=0,\u8bb0\u4f5c0\u79cd\u653e\u6cd5
\u5f53\u82f9\u679c\u6570\u5c0f\u4e8e\u7bee\u5b50\u6570\u65f6\u5019\uff0c\u5373m<n\u65f6\uff0c\u5176\u653e\u6cd5\u548cm\u4e2a\u82f9\u679c\uff0cm\u4e2a\u7bee\u5b50\u7684\u60c5\u51b5\u65f6\u76f8\u7b49
\u5f53\u82f9\u679c\u6570\u5927\u4e8e\u6216\u8005\u7b49\u4e8e\u7bee\u5b50\u6570\u65f6\u5019\uff0c\u5373m>=n\u65f6,\u53c8\u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5
\u4e00\u79cd\u662f\u6bcf\u4e2a\u7bee\u5b50\u90fd\u81f3\u5c11\u6709\u4e00\u4e2a\u82f9\u679c\u7684\u65f6\u5019\uff0c\u4e00\u79cd\u662f\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u7bee\u5b50\u7684\u65f6\u5019<\/p>\n

\u4ee3\u7801\uff1a<\/p>\n

 import<\/span> java.<\/span>util.<\/span>Scanner;<\/span>\n    \n    public<\/span> class<\/span> AppleAndBasket<\/span> { \n   <\/span>\n        \/* * \u95ee\u9898\uff1a\u6709m\u4e2a\u82f9\u679c\u548cn\u4e2a\u7bee\u5b50\uff0c\u6709\u51e0\u79cd\u653e\u6cd5\uff1f\u7bee\u5b50\u53ef\u4ee5\u4e3a\u7a7a\uff08131\u548c113\u662f\u4e00\u79cd\u653e\u6cd5\uff09 * * \u5206\u6790\uff1a\u5f53m=0,\u6216\u8005n=1\u65f6\u5019\uff0c\u53ea\u6709\u4e00\u79cd\u653e\u6cd5\uff0c\u7bee\u5b50\u53ea\u6709\u4e00\u4e2a\uff0c * \u5f53n=0,\u8bb0\u4f5c0\u79cd\u653e\u6cd5 * \u5f53\u82f9\u679c\u6570\u5c0f\u4e8e\u7bee\u5b50\u6570\u65f6\u5019\uff0c\u5373m<n\u65f6\uff0c\u653e\u6cd5\u548cm\u4e2a\u82f9\u679c\uff0cm\u4e2a\u7bee\u5b50\u7684\u60c5\u51b5\u65f6\u76f8\u7b49 * \u5f53\u82f9\u679c\u6570\u5927\u4e8e\u6216\u8005\u7b49\u4e8e\u7bee\u5b50\u6570\u65f6\u5019\uff0c\u53c8\u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5 * \u4e00\u79cd\u662f\u7bee\u5b50\u90fd\u6ee1\u7684\u65f6\u5019\uff0c\u4e00\u79cd\u662f\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u7bee\u5b50\u7684\u65f6\u5019 * * *\/<\/span>\n    \n        public<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String[<\/span>]<\/span> args)<\/span> { \n   <\/span>\n            Scanner scanner =<\/span> new<\/span> Scanner<\/span>(<\/span>System.<\/span>in)<\/span>;<\/span>\n            System.<\/span>out.<\/span>println<\/span>(<\/span>\"\u8bf7\u8f93\u5165\u7bee\u5b50\u6570\"<\/span>)<\/span>;<\/span>\n            int<\/span> n =<\/span> scanner.<\/span>nextInt<\/span>(<\/span>)<\/span>;<\/span>\n            System.<\/span>out.<\/span>println<\/span>(<\/span>\"\u8bf7\u8f93\u5165\u82f9\u679c\u6570\"<\/span>)<\/span>;<\/span>\n            int<\/span> m =<\/span> scanner.<\/span>nextInt<\/span>(<\/span>)<\/span>;<\/span>\n            int<\/span> i =<\/span> method<\/span>(<\/span>n,<\/span>m)<\/span>;<\/span>\n            System.<\/span>out.<\/span>println<\/span>(<\/span>i)<\/span>;<\/span>\n        }<\/span>\n    \n        private<\/span> static<\/span> int<\/span> method<\/span>(<\/span>int<\/span> n,<\/span> int<\/span> m)<\/span> { \n   <\/span>\n            if<\/span> (<\/span>n ==<\/span> 1<\/span> ||<\/span> m ==<\/span> 0<\/span>)<\/span> { \n   <\/span>\n                return<\/span> 1<\/span>;<\/span>\n            }<\/span>\n            if<\/span> (<\/span>n ==<\/span> 0<\/span>)<\/span> { \n   <\/span>\n                return<\/span> 0<\/span>;<\/span>\n            }<\/span>\n            \/\/\u82f9\u679c\u6570\u5c0f\u4e8e\u7bee\u5b50\u6570\uff0c\u53732\u4e2a\u82f9\u679c\u653e5\u4e2a\u7bee\u5b50\uff0c\u548c2\u4e2a\u82f9\u679c\u653e2\u4e2a\u7bee\u5b50\u7684\u653e\u6cd5\u662f\u4e00\u6837\u7684<\/span>\n            if<\/span> (<\/span>m <<\/span> n)<\/span> { \n   <\/span>\n                return<\/span> method<\/span>(<\/span>m,<\/span>m)<\/span>;<\/span>\n            }<\/span>\n            \/\/\u82f9\u679c\u6570\u5927\u4e8e\u7b49\u4e8e\u7bee\u5b50\u6570,\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5<\/span>\n            if<\/span> (<\/span>m >=<\/span> n)<\/span> { \n   <\/span>\n                \/\/\u60c5\u51b5\u4e00\uff1a\u6bcf\u4e2a\u7bee\u5b50\u91cc\u9762\u90fd\u653e\u6709\u4e00\u4e2a\u82f9\u679c\uff0c\u51b3\u5b9a\u653e\u6cd5\u6570\u7684\u5c31\u662f\u5269\u4f59\u82f9\u679c\u5728n\u4e2a\u7bee\u5b50\u7684\u653e\u6cd5\u6570<\/span>\n                \/\/\u60c5\u51b5\u4e8c\uff1a\u81f3\u5c11\u6709\u4e00\u4e2a\u7a7a\u7bee\u5b50\uff0c\u5373m\u4e2a\u82f9\u679c\u5728n-1\u4e2a\u7bee\u5b50\u7684\u60c5\u51b5\u4e0b\u7684\u65b9\u6cd5<\/span>\n                return<\/span> method<\/span>(<\/span>n,<\/span>m-<\/span>n)<\/span>+<\/span> method<\/span>(<\/span>n-<\/span>1<\/span>,<\/span>m)<\/span>;<\/span>\n            }<\/span>\n            return<\/span> 0<\/span>;<\/span>\n        }<\/span>\n    }<\/span>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"M\u4e2a\u82f9\u679c\u653eN\u4e2a\u7bee\u5b50\uff0c\u7bee\u5b50\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u6709\u591a\u5c11\u79cd\u653e\u6cd5\uff1f\u95ee\u9898\uff1aM\u4e2a\u82f9\u679c\u653eN\u4e2a\u7bee\u5b50\uff0c\u7bee\u5b50\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u6709\u591a\u5c11\u79cd\u653e\u6cd5\uff1f\u5206\u6790\uff1a\u5f53m=0,\u6216\u8005n=1...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9108"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=9108"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9108\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=9108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=9108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=9108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}