{"id":33376,"date":"2024-11-01T09:15:59","date_gmt":"2024-11-01T09:15:59","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33376"},"modified":"2024-11-01T11:38:57","modified_gmt":"2024-11-01T11:38:57","slug":"java-coding-test-course-i-will-become-the-president-of-the-residents-association","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33376\/","title":{"rendered":"Java Coding Test Course, I Will Become the President of the Residents&#8217; Association"},"content":{"rendered":"<p><body><\/p>\n<p>In this article, we will look at one of the famous problems in Java coding tests, the &#8220;I Will Become the Apartment Manager&#8221; problem.<br \/>\n    This problem serves as a good example to learn the basics of dynamic programming, and I will detail the process of solving the given problem through an efficient algorithm.<\/p>\n<h2>Problem Description<\/h2>\n<p>The goal of the &#8220;I Will Become the Apartment Manager&#8221; problem is as follows. <\/p>\n<p><strong>Problem:<\/strong> <br \/>\n    Assume there are N floors and K apartments. Write an algorithm to calculate the number of people living in apartment N on the Kth floor. <\/p>\n<p>    Each apartment has a problem to find the number of people living in apartment N on the Kth floor. There is 1 person on the ground floor, and the number of people in apartment N on each floor is the sum of the number of people in all apartments on the floor below. Therefore, <\/p>\n<ul>\n<li>1st floor apartment 1 = 1<\/li>\n<li>1st floor apartment 2 = 1<\/li>\n<li>2nd floor apartment 1 = 1<\/li>\n<li>2nd floor apartment 2 = 1 + 1 = 2<\/li>\n<li>3rd floor apartment 1 = 1<\/li>\n<li>3rd floor apartment 2 = 1 + 2 = 3<\/li>\n<\/ul>\n<p>    This pattern emerges. <\/p>\n<p>    For the given K and N, please create a function that calculates the number of people living in that apartment.<\/p>\n<h2>Input and Output Format<\/h2>\n<p><strong>Input:<\/strong> The first line gives the number of test cases T (1 \u2264 T \u2264 14). <br \/>\n    Each test case consists of two integers K and N (0 \u2264 K \u2264 14, 1 \u2264 N \u2264 14). <br \/>\n<strong>Output:<\/strong> For each test case, print the number of people living in apartment N on the Kth floor.<\/p>\n<h2>Problem Solving Process<\/h2>\n<h3>Step 1: Understanding the Problem<\/h3>\n<p>The essence of the problem is to understand the pattern of the number of people from the ground floor to the Kth floor, and based on this pattern, to find the number of people in apartment N.<br \/>\n    As I understand, the apartment problem can apply the rules of dynamic programming.<br \/>\n    In other words, the value of apartment N on each floor can be defined as the sum of the values in apartments N and (N-1) on the previous floor.<\/p>\n<h3>Step 2: Designing the Dynamic Programming Table<\/h3>\n<p>To solve this problem, we will declare a 2D array to calculate the number of people in Kth floor apartment N.<br \/>\n    We will proceed by filling in the array with the number of people at each position.<\/p>\n<pre>\n    \/\/ Example Java code\n    int[][] dp = new int[15][15]; \/\/ Declare a 15 x 15 array\n    for (int i = 0; i &lt; 15; i++) {\n        dp[i][1] = 1; \/\/ Initialize all apartments on the ground floor\n        dp[0][i] = i; \/\/ Set the number of people on the ground floor\n    }\n    \n    for (int i = 1; i &lt; 15; i++) {\n        for (int j = 2; j &lt; 15; j++) {\n            dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; \/\/ Dynamic programming recurrence relation\n        }\n    }\n    <\/pre>\n<h3>Step 3: Final Calculation<\/h3>\n<p>Based on the above rules, we can calculate the value for Kth floor apartment N. For each test case, we simply need to print the value of dp[K][N].<\/p>\n<h3>Step 4: Code Implementation<\/h3>\n<pre>\n    import java.util.Scanner;\n\n    public class Main {\n        public static void main(String[] args) {\n            Scanner sc = new Scanner(System.in);\n            int T = sc.nextInt(); \/\/ Number of test cases\n            int[][] dp = new int[15][15]; \/\/ 15x15 array\n\n            \/\/ Initialize the DP array\n            for (int i = 0; i &lt; 15; i++) {\n                dp[i][1] = 1; \/\/ Initialize all apartments on the ground floor\n                dp[0][i] = i; \/\/ Set the number of people on the ground floor\n            }\n\n            \/\/ Fill the DP table\n            for (int i = 1; i &lt; 15; i++) {\n                for (int j = 2; j &lt; 15; j++) {\n                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; \/\/ Recurrence relation\n                }\n            }\n\n            \/\/ Process each test case\n            for (int t = 0; t &lt; T; t++) {\n                int K = sc.nextInt(); \/\/ Floor number\n                int N = sc.nextInt(); \/\/ Apartment number\n                System.out.println(dp[K][N]); \/\/ Print the result\n            }\n\n            sc.close();\n        }\n    }\n    <\/pre>\n<h2>Conclusion<\/h2>\n<p>I hope that through this lesson, you have gained a basic understanding of dynamic programming related to solving the &#8220;I Will Become the Apartment Manager&#8221; problem.<br \/>\n    This problem serves as a good example to learn important principles in algorithm design and implementation.<br \/>\n    By applying such patterns to various problems, you can solve more complex issues relatively easily.<br \/>\n    Practice with more types of problems!<\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.acmicpc.net\/problem\/2775\">BOJ 2775: I Will Become the Apartment Manager<\/a><\/li>\n<li><a href=\"https:\/\/www.geeksforgeeks.org\/dynamic-programming-set-2-fibonacci-number\/\">Dynamic Programming &#8211; Fibonacci Sequence<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will look at one of the famous problems in Java coding tests, the &#8220;I Will Become the Apartment Manager&#8221; problem. This problem serves as a good example to learn the basics of dynamic programming, and I will detail the process of solving the given problem through an efficient algorithm. Problem Description &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33376\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, I Will Become the President of the Residents&#8217; 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":[139],"tags":[],"class_list":["post-33376","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, I Will Become the President of the Residents&#039; 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\/33376\/\" \/>\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, I Will Become the President of the Residents&#039; Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this article, we will look at one of the famous problems in Java coding tests, the &#8220;I Will Become the Apartment Manager&#8221; problem. This problem serves as a good example to learn the basics of dynamic programming, and I will detail the process of solving the given problem through an efficient algorithm. Problem Description &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, I Will Become the President of the Residents&#8217; Association&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33376\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:15:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:38:57+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\/33376\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33376\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, I Will Become the President of the Residents&#8217; Association\",\"datePublished\":\"2024-11-01T09:15:59+00:00\",\"dateModified\":\"2024-11-01T11:38:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33376\/\"},\"wordCount\":490,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33376\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33376\/\",\"name\":\"Java Coding Test Course, I Will Become the President of the Residents' Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:15:59+00:00\",\"dateModified\":\"2024-11-01T11:38:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33376\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33376\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33376\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, I Will Become the President of the Residents&#8217; 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":"Java Coding Test Course, I Will Become the President of the Residents' 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\/33376\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, I Will Become the President of the Residents' Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this article, we will look at one of the famous problems in Java coding tests, the &#8220;I Will Become the Apartment Manager&#8221; problem. This problem serves as a good example to learn the basics of dynamic programming, and I will detail the process of solving the given problem through an efficient algorithm. Problem Description &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, I Will Become the President of the Residents&#8217; Association\"","og_url":"https:\/\/atmokpo.com\/w\/33376\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:15:59+00:00","article_modified_time":"2024-11-01T11:38:57+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\/33376\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33376\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, I Will Become the President of the Residents&#8217; Association","datePublished":"2024-11-01T09:15:59+00:00","dateModified":"2024-11-01T11:38:57+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33376\/"},"wordCount":490,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33376\/","url":"https:\/\/atmokpo.com\/w\/33376\/","name":"Java Coding Test Course, I Will Become the President of the Residents' Association - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:15:59+00:00","dateModified":"2024-11-01T11:38:57+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33376\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33376\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33376\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, I Will Become the President of the Residents&#8217; 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\/33376","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=33376"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33376\/revisions"}],"predecessor-version":[{"id":33377,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33376\/revisions\/33377"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}