{"id":33309,"date":"2024-11-01T09:15:24","date_gmt":"2024-11-01T09:15:24","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33309"},"modified":"2024-11-01T11:39:15","modified_gmt":"2024-11-01T11:39:15","slug":"java-coding-test-course-finding-the-number-of-steps","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33309\/","title":{"rendered":"Java Coding Test Course, Finding the Number of Steps"},"content":{"rendered":"<p><body><\/p>\n<header>\n<p>Let&#8217;s improve our problem-solving skills in actual exams by solving various algorithm problems in preparation for the coding test.<\/p>\n<\/header>\n<p><main><\/p>\n<section>\n<h2>Problem Description<\/h2>\n<p>\n                Stair numbers follow the following rules. They are n-digit numbers, and each digit must increase in ascending order. That is, the difference between two adjacent digits must be exactly 1. For example, 123, 234, and 345 are all stair numbers.\n            <\/p>\n<h3>Problem<\/h3>\n<p>\n                Write a program to find the number of N-digit stair numbers given N.\n            <\/p>\n<h3>Input<\/h3>\n<ul>\n<li>Natural number N is given in the first line. (1 \u2264 N \u2264 100)<\/li>\n<\/ul>\n<h3>Output<\/h3>\n<ul>\n<li>Print the number of N-digit stair numbers modulo 10007.<\/li>\n<\/ul>\n<h3>Example Input<\/h3>\n<pre>3<\/pre>\n<h3>Example Output<\/h3>\n<pre>14<\/pre>\n<h3>Explanation<\/h3>\n<p>\n                If N is 3, the 3-digit stair numbers are 123, 132, 210, 321, 234, 345, 456, 567, 678, 789, etc., totaling 14.\n            <\/p>\n<\/section>\n<section>\n<h2>Solution Process<\/h2>\n<p>\n                To solve this problem, we can use the technique of Dynamic Programming.\n            <\/p>\n<p>\n                Stair numbers can be thought of as combinations of N-digit numbers based on the previous N-1 digit numbers. The last digit of the N-digit number is determined by the last digit of the N-1 digit numbers, so we simply update the DP array considering this.\n            <\/p>\n<h3>Solution Approach<\/h3>\n<ol>\n<li>\n<strong>State Definition<\/strong>: Define dp[n][last] as the number of n-digit stair numbers where the last digit is last. n refers to the number of digits, and last refers to the last digit (0-9).\n                <\/li>\n<li>\n<strong>Initial State Setup<\/strong>: For 1-digit numbers (i.e., when N=1), each digit (1-9) has exactly 1 case. Thus, dp[1][1] to dp[1][9] will be 1, and dp[1][0] will be 0.\n                <\/li>\n<li>\n<strong>State Transition<\/strong>: n-digit numbers are created from n-1 digit numbers. When the last digit is last, the last digit can either be last-1 or last+1. This can be expressed as follows: <\/p>\n<pre>\n                    dp[n][last] = dp[n-1][last-1] + dp[n-1][last+1]\n                    <\/pre>\n<p>                    Here, last can take values from 1 to 8 (0 and 9 are limited to one side).\n                <\/li>\n<li>\n<strong>Result Calculation<\/strong>: The number of N-digit numbers is the sum of dp[N][0] + dp[N][1] + &#8230; + dp[N][9]. However, since the problem requires the result modulo 10007, this operation must be performed during the calculation.\n                <\/li>\n<\/ol>\n<\/section>\n<section>\n<h2>Java Code Implementation<\/h2>\n<pre>\n                import java.util.Scanner;\n\n                public class StairNumber {\n                    public static void main(String[] args) {\n                        Scanner sc = new Scanner(System.in);\n                        int N = sc.nextInt();\n                        int MOD = 10007;\n\n                        \/\/ Initialize DP array\n                        int[][] dp = new int[N + 1][10];\n\n                        \/\/ Initialize 1-digit numbers\n                        for (int i = 1; i &lt; 10; i++) {\n                            dp[1][i] = 1;\n                        }\n\n                        \/\/ Build DP table\n                        for (int n = 2; n &lt;= N; n++) {\n                            for (int last = 0; last &lt;= 9; last++) {\n                                if (last &gt; 0) { \/\/ If last is not 0\n                                    dp[n][last] += dp[n - 1][last - 1];\n                                }\n                                if (last &lt; 9) { \/\/ If last is not 9\n                                    dp[n][last] += dp[n - 1][last + 1];\n                                }\n                                dp[n][last] %= MOD; \/\/ MOD operation\n                            }\n                        }\n\n                        \/\/ Summarize results\n                        int result = 0;\n                        for (int last = 0; last &lt;= 9; last++) {\n                            result = (result + dp[N][last]) % MOD;\n                        }\n\n                        \/\/ Output result\n                        System.out.println(result);\n                        sc.close();\n                    }\n                }\n            <\/pre>\n<\/section>\n<section>\n<h2>Example<\/h2>\n<h3>Input<\/h3>\n<pre>3<\/pre>\n<h3>Output<\/h3>\n<pre>14<\/pre>\n<p>When running the above code, you can accurately calculate the number of 3-digit stair numbers.<\/p>\n<\/section>\n<section>\n<h2>Additional Notes<\/h2>\n<p>\n                After solving the problem, it is important to verify the algorithm&#8217;s accuracy with various test cases. Additionally, optimizing the code or approaching the algorithm in different ways and comparing the results is also a good practice.\n            <\/p>\n<p>\n                Finally, dynamic programming problems can often be related to graph theory, so it&#8217;s essential to maintain this perspective when solving problems.\n            <\/p>\n<\/section>\n<p><\/main><\/p>\n<footer>\n<p>I hope this helps a lot! Start with basic algorithms and gradually move on to more complex problems.<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s improve our problem-solving skills in actual exams by solving various algorithm problems in preparation for the coding test. Problem Description Stair numbers follow the following rules. They are n-digit numbers, and each digit must increase in ascending order. That is, the difference between two adjacent digits must be exactly 1. For example, 123, 234, &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33309\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Finding the Number of Steps&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[139],"tags":[],"class_list":["post-33309","post","type-post","status-publish","format-standard","hentry","category-java-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Coding Test Course, Finding the Number of Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/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:\/\/atmokpo.com\/w\/33309\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Coding Test Course, Finding the Number of Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Let&#8217;s improve our problem-solving skills in actual exams by solving various algorithm problems in preparation for the coding test. Problem Description Stair numbers follow the following rules. They are n-digit numbers, and each digit must increase in ascending order. That is, the difference between two adjacent digits must be exactly 1. For example, 123, 234, &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Finding the Number of Steps&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33309\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:15:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:39:15+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33309\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33309\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Finding the Number of Steps\",\"datePublished\":\"2024-11-01T09:15:24+00:00\",\"dateModified\":\"2024-11-01T11:39:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33309\/\"},\"wordCount\":414,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33309\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33309\/\",\"name\":\"Java Coding Test Course, Finding the Number of Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:15:24+00:00\",\"dateModified\":\"2024-11-01T11:39:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33309\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33309\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33309\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Finding the Number of Steps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Coding Test Course, Finding the Number of Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/33309\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Finding the Number of Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Let&#8217;s improve our problem-solving skills in actual exams by solving various algorithm problems in preparation for the coding test. Problem Description Stair numbers follow the following rules. They are n-digit numbers, and each digit must increase in ascending order. That is, the difference between two adjacent digits must be exactly 1. For example, 123, 234, &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Finding the Number of Steps\"","og_url":"https:\/\/atmokpo.com\/w\/33309\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:15:24+00:00","article_modified_time":"2024-11-01T11:39:15+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33309\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33309\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Finding the Number of Steps","datePublished":"2024-11-01T09:15:24+00:00","dateModified":"2024-11-01T11:39:15+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33309\/"},"wordCount":414,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33309\/","url":"https:\/\/atmokpo.com\/w\/33309\/","name":"Java Coding Test Course, Finding the Number of Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:15:24+00:00","dateModified":"2024-11-01T11:39:15+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33309\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33309\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33309\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Finding the Number of Steps"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=33309"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33309\/revisions"}],"predecessor-version":[{"id":33310,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33309\/revisions\/33310"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}