{"id":34042,"date":"2024-11-01T09:23:27","date_gmt":"2024-11-01T09:23:27","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34042"},"modified":"2024-11-01T10:53:53","modified_gmt":"2024-11-01T10:53:53","slug":"c-coding-test-course-counting-steps","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34042\/","title":{"rendered":"C# Coding Test Course, Counting Steps"},"content":{"rendered":"<p><body><\/p>\n<article>\n<section>\n<h2>1. Problem Description<\/h2>\n<p>\n                The staircase number is a problem of counting numbers that meet specific conditions.<br \/>\n                Given a number N, we will address the problem of finding N-digit staircase numbers.<br \/>\n                A staircase number is a number where each digit must be either one more or one less than the next digit. For example, 1234 and 3210 are staircase numbers.<br \/>\n                However, 1123 and 2222 are not staircase numbers.<br \/>\n                This problem will help you understand the basic ideas and implementation methods of dynamic programming.\n            <\/p>\n<\/section>\n<section>\n<h2>2. Input &amp; Output Format<\/h2>\n<h3>Input<\/h3>\n<p>N (1 \u2264 N \u2264 100), the given natural number N represents the number of digits in the staircase number.<\/p>\n<h3>Output<\/h3>\n<p>Print the number of N-digit staircase numbers modulo 1,000,000,000.<\/p>\n<\/section>\n<section>\n<h2>3. Approach to the Problem<\/h2>\n<p>\n                To count staircase numbers, we need to choose a dynamic programming method.<br \/>\n                We can approach the problem in the following way.<br \/>\n                To find N-digit staircase numbers, we calculate values using (N-1)-digit staircase numbers.<br \/>\n                We can find the following rules:\n            <\/p>\n<ul>\n<li>If each digit is 0, the next digit can only be 1.<\/li>\n<li>If each digit is 9, the next digit can only be 8.<\/li>\n<li>If each digit is between 1 and 8, there are two options for the next digit: one less or one more.<\/li>\n<\/ul>\n<p>\n                Based on this, we can construct a DP table and keep track of staircase numbers for each digit,<br \/>\n                ultimately allowing us to find the N-digit staircase numbers.<br \/>\n                The approach involves initializing the DP array and gradually filling it out.\n            <\/p>\n<\/section>\n<section>\n<h2>4. C# Code Implementation<\/h2>\n<p>\n                Now we will implement the code to find staircase numbers in C#.<br \/>\n                Below is the C# code to solve the problem.\n            <\/p>\n<pre><code>\nusing System;\n\nclass Program\n{\n    static void Main()\n    {\n        int N = int.Parse(Console.ReadLine());\n        long[,] dp = new long[N + 1, 10];\n\n        \/\/ Initialize 1-digit staircase numbers (1~9)\n        for (int i = 1; i &lt;= 9; i++)\n        {\n            dp[1, i] = 1;\n        }\n\n        \/\/ Use DP to find N-digit staircase numbers\n        for (int i = 2; i &lt;= N; i++)\n        {\n            for (int j = 0; j &lt;= 9; j++)\n            {\n                if (j == 0)\n                {\n                    dp[i, j] = dp[i - 1, j + 1] % 1000000000; \/\/ 0 -&gt; 1\n                }\n                else if (j == 9)\n                {\n                    dp[i, j] = dp[i - 1, j - 1] % 1000000000; \/\/ 9 -&gt; 8\n                }\n                else\n                {\n                    dp[i, j] = (dp[i - 1, j - 1] + dp[i - 1, j + 1]) % 1000000000; \/\/ j-1, j+1\n                }\n            }\n        }\n\n        \/\/ Calculate the total number of N-digit staircase numbers\n        long result = 0;\n        for (int j = 0; j &lt;= 9; j++)\n        {\n            result = (result + dp[N, j]) % 1000000000;\n        }\n\n        \/\/ Print the result\n        Console.WriteLine(result);\n    }\n}\n            <\/code><\/pre>\n<\/section>\n<section>\n<h2>5. Code Explanation<\/h2>\n<p>\n                I will explain the code step by step.<br \/>\n                1. First, read the value of N from the user&#8217;s input.<br \/>\n                2. Create a two-dimensional array dp, where dp[i, j] stores the number of i-digit staircase numbers ending with j.<br \/>\n                3. Since 1-digit numbers can only use digits from 1 to 9, we initialize this.<br \/>\n                4. Next, we calculate the number of digits from 2 up to N.<br \/>\n                5. Each digit&#8217;s calculation is done according to the rules explained above.<br \/>\n                6. Finally, sum all N-digit staircase numbers and print the result.\n            <\/p>\n<\/section>\n<section>\n<h2>6. Complexity Analysis<\/h2>\n<p>\n                The time complexity of this algorithm is O(N).<br \/>\n                When N is 100, we check the possibilities for each digit through a double loop,<br \/>\n                which results in O(N) * O(10) = O(N).<br \/>\n                The space complexity is O(N * 10), indicating relatively low memory usage.\n            <\/p>\n<\/section>\n<section>\n<h2>7. Example<\/h2>\n<h3>Input Example<\/h3>\n<pre><code>\n3\n            <\/code><\/pre>\n<h3>Output Example<\/h3>\n<pre><code>\n32\n            <\/code><\/pre>\n<p>\n                In the above example, there are 32 three-digit staircase numbers.<br \/>\n                This helps to understand the problem.\n            <\/p>\n<\/section>\n<section>\n<h2>8. Conclusion<\/h2>\n<p>\n                In this tutorial, we learned the basic concepts of dynamic programming<br \/>\n                through the problem of finding staircase numbers.<br \/>\n                The staircase number problem can serve as a good practice problem to improve algorithm skills.<br \/>\n                I hope you gain more experience by solving various problems.<br \/>\n                Continue to challenge yourself with algorithm problem-solving!\n            <\/p>\n<\/section>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Problem Description The staircase number is a problem of counting numbers that meet specific conditions. Given a number N, we will address the problem of finding N-digit staircase numbers. A staircase number is a number where each digit must be either one more or one less than the next digit. For example, 1234 and &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34042\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C# Coding Test Course, Counting 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":[90],"tags":[],"class_list":["post-34042","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Coding Test Course, Counting 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\/34042\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Coding Test Course, Counting Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"1. Problem Description The staircase number is a problem of counting numbers that meet specific conditions. Given a number N, we will address the problem of finding N-digit staircase numbers. A staircase number is a number where each digit must be either one more or one less than the next digit. For example, 1234 and &hellip; \ub354 \ubcf4\uae30 &quot;C# Coding Test Course, Counting Steps&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34042\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:23:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:53:53+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\/34042\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34042\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C# Coding Test Course, Counting Steps\",\"datePublished\":\"2024-11-01T09:23:27+00:00\",\"dateModified\":\"2024-11-01T10:53:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34042\/\"},\"wordCount\":459,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C# Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34042\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34042\/\",\"name\":\"C# Coding Test Course, Counting Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:23:27+00:00\",\"dateModified\":\"2024-11-01T10:53:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34042\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34042\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34042\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Coding Test Course, Counting 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":"C# Coding Test Course, Counting 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\/34042\/","og_locale":"ko_KR","og_type":"article","og_title":"C# Coding Test Course, Counting Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"1. Problem Description The staircase number is a problem of counting numbers that meet specific conditions. Given a number N, we will address the problem of finding N-digit staircase numbers. A staircase number is a number where each digit must be either one more or one less than the next digit. For example, 1234 and &hellip; \ub354 \ubcf4\uae30 \"C# Coding Test Course, Counting Steps\"","og_url":"https:\/\/atmokpo.com\/w\/34042\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:23:27+00:00","article_modified_time":"2024-11-01T10:53:53+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\/34042\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34042\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C# Coding Test Course, Counting Steps","datePublished":"2024-11-01T09:23:27+00:00","dateModified":"2024-11-01T10:53:53+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34042\/"},"wordCount":459,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C# Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34042\/","url":"https:\/\/atmokpo.com\/w\/34042\/","name":"C# Coding Test Course, Counting Steps - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:23:27+00:00","dateModified":"2024-11-01T10:53:53+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34042\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34042\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34042\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C# Coding Test Course, Counting 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\/34042","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=34042"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34042\/revisions"}],"predecessor-version":[{"id":34043,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34042\/revisions\/34043"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}