{"id":34742,"date":"2024-11-01T09:31:29","date_gmt":"2024-11-01T09:31:29","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34742"},"modified":"2024-11-01T11:26:44","modified_gmt":"2024-11-01T11:26:44","slug":"swift-coding-test-course-i-will-become-the-president-of-the-womens-association","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34742\/","title":{"rendered":"Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association"},"content":{"rendered":"<p><body><\/p>\n<p>\n    Hello, everyone! In this post, we will address one of the algorithm problems called &#8220;I Will Be the Apartment Leader&#8221;.<br \/>\n    This problem is one of the frequently asked topics in Swift coding tests.<br \/>\n    I will explain the basic problem description, the process of solving it, and how to implement the code in detail.\n<\/p>\n<h2>Problem Description<\/h2>\n<p>\n    The &#8220;I Will Be the Apartment Leader&#8221; problem is about calculating the number of residents in an apartment according to specific rules.<br \/>\n    The given apartment consists of N floors and K units.<br \/>\n    The number of residents in each unit on the K-th floor follows these rules:\n<\/p>\n<ul>\n<li>On the 0-th floor, there is 1 resident in every K unit.<\/li>\n<li>The number of residents in unit n on the k-th floor is the sum of the number of residents from unit 1 to n on the (k-1)-th floor.<\/li>\n<\/ul>\n<p>\n    In other words, the number of residents on the 0-th floor is 1 for everyone, and the number of residents in unit n on the 1st floor is the total from unit 1 to n on the 0-th floor.<br \/>\n    We can use these rules to calculate the number of residents in unit n on the k-th floor.\n<\/p>\n<h2>Input and Output Format<\/h2>\n<h3>Input<\/h3>\n<ul>\n<li>The first line contains the number of test cases T. (1 \u2264 T \u2264 100)<\/li>\n<li>Each test case consists of two integers K and N. (0 \u2264 K \u2264 14, 1 \u2264 N \u2264 14)<\/li>\n<\/ul>\n<h3>Output<\/h3>\n<ul>\n<li>For each test case, print the number of residents in unit N on the k-th floor.<\/li>\n<\/ul>\n<h2>Process of Solving the Problem<\/h2>\n<p>\n    To solve this problem, we first declare a 2-dimensional array to calculate the number of residents in the apartment.<br \/>\n    The size of the array is set to (15 x 15) to store the number of residents from the 0-th floor to the 14-th floor.<br \/>\n    We will use this to solve the problem using Dynamic Programming.\n<\/p>\n<h3>Step 1: Initialize the Array<\/h3>\n<pre><code>\nlet maxK = 15\nlet maxN = 15\nvar dp = Array(repeating: Array(repeating: 0, count: maxN), count: maxK)\n\nfor i in 0..<maxN {\n    dp[0][i] = 1\n}\n<\/code><\/pre>\n<p>\n    Here, dp[k][n] represents the number of residents in unit n on the k-th floor.<br \/>\n    We initialized all values on the 0-th floor to 1. For k > 0, we can calculate dp[k][n] as the sum of residents from the previous floor.\n<\/p>\n<h3>Step 2: Calculate the Number of Residents<\/h3>\n<pre><code>\nfor k in 1..<maxK {\n    for n in 0..<maxN {\n        for j in 1...n {\n            dp[k][n] += dp[k-1][j]\n        }\n    }\n}\n<\/code><\/pre>\n<p>\n    This is the process of filling the dp array with values.<br \/>\n    The number of residents in unit n on the k-th floor is the sum from units 1 to n on the (k-1)-th floor.<br \/>\n    We calculate the values for each floor and store them in the dp array through a loop.\n<\/p>\n<h3>Step 3: Print the Results<\/h3>\n<pre><code>\nfor _ in 0..<t {\n    let K = Int(input[0]) \/\/ Input value\n    let N = Int(input[1]) \/\/ Input value\n    print(dp[K][N-1]) \/\/ Output the result\n}\n<\/code><\/pre>\n<p>\n    Finally, we print the number of residents in unit N on the k-th floor for each test case.<br \/>\n    Through this process, we can solve the problem.\n<\/p>\n<h2>Implementation Code<\/h2>\n<p>\n    Now, the full code that implements the above process in Swift is below.\n<\/p>\n<pre><code>\nimport Foundation\n\nlet maxK = 15\nlet maxN = 15\nvar dp = Array(repeating: Array(repeating: 0, count: maxN), count: maxK)\n\nfor i in 0..<maxN {\n    dp[0][i] = 1\n}\nfor k in 1..<maxK {\n    for n in 0..<maxN {\n        for j in 1...n {\n            dp[k][n] += dp[k-1][j]\n        }\n    }\n}\nlet t = Int(readLine()!)!\nfor _ in 0..<t {\n    let input = readLine()!.split(separator: \" \").map { Int(String($0))! }\n    let K = input[0] \/\/ K value\n    let N = input[1] \/\/ N value\n    print(dp[K][N-1]) \/\/ Output\n}\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>\n    In this article, we examined the process of solving the \"I Will Be the Apartment Leader\" problem.<br \/>\n    We learned how to understand the rules of the problem and efficiently calculate the solution using Dynamic Programming.<br \/>\n    I hope this helps you solidify your understanding of algorithms and prepare for coding tests.<br \/>\n    Thank you!\n<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, everyone! In this post, we will address one of the algorithm problems called &#8220;I Will Be the Apartment Leader&#8221;. This problem is one of the frequently asked topics in Swift coding tests. I will explain the basic problem description, the process of solving it, and how to implement the code in detail. Problem Description &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34742\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association&#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":[129],"tags":[],"class_list":["post-34742","post","type-post","status-publish","format-standard","hentry","category-swift-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Swift Coding Test Course, I Will Become the President of the Women&#039;s Association - \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\/34742\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift Coding Test Course, I Will Become the President of the Women&#039;s Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello, everyone! In this post, we will address one of the algorithm problems called &#8220;I Will Be the Apartment Leader&#8221;. This problem is one of the frequently asked topics in Swift coding tests. I will explain the basic problem description, the process of solving it, and how to implement the code in detail. Problem Description &hellip; \ub354 \ubcf4\uae30 &quot;Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34742\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:31:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:26:44+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=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34742\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34742\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association\",\"datePublished\":\"2024-11-01T09:31:29+00:00\",\"dateModified\":\"2024-11-01T11:26:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34742\/\"},\"wordCount\":513,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34742\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34742\/\",\"name\":\"Swift Coding Test Course, I Will Become the President of the Women's Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:31:29+00:00\",\"dateModified\":\"2024-11-01T11:26:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34742\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34742\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34742\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association\"}]},{\"@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":"Swift Coding Test Course, I Will Become the President of the Women's Association - \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\/34742\/","og_locale":"ko_KR","og_type":"article","og_title":"Swift Coding Test Course, I Will Become the President of the Women's Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello, everyone! In this post, we will address one of the algorithm problems called &#8220;I Will Be the Apartment Leader&#8221;. This problem is one of the frequently asked topics in Swift coding tests. I will explain the basic problem description, the process of solving it, and how to implement the code in detail. Problem Description &hellip; \ub354 \ubcf4\uae30 \"Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association\"","og_url":"https:\/\/atmokpo.com\/w\/34742\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:31:29+00:00","article_modified_time":"2024-11-01T11:26:44+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":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34742\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34742\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association","datePublished":"2024-11-01T09:31:29+00:00","dateModified":"2024-11-01T11:26:44+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34742\/"},"wordCount":513,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34742\/","url":"https:\/\/atmokpo.com\/w\/34742\/","name":"Swift Coding Test Course, I Will Become the President of the Women's Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:31:29+00:00","dateModified":"2024-11-01T11:26:44+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34742\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34742\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34742\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Swift Coding Test Course, I Will Become the President of the Women&#8217;s Association"}]},{"@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\/34742","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=34742"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34742\/revisions"}],"predecessor-version":[{"id":34743,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34742\/revisions\/34743"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}