{"id":58,"date":"2011-09-02T02:21:44","date_gmt":"2011-09-02T02:21:44","guid":{"rendered":"http:\/\/www.uturtle.com\/blog\/archives\/58"},"modified":"2013-05-12T19:16:03","modified_gmt":"2013-05-12T19:16:03","slug":"uva-counting-10198","status":"publish","type":"post","link":"https:\/\/www.jinukbaek.com\/blog\/ko\/archives\/58","title":{"rendered":"[UVA] Counting &#8211; 10198"},"content":{"rendered":"<p>\ucc98\uc74c\uc5d0 C\uc5b8\uc5b4\ub85c \uc9f0\uc73c\ub098 1000\uc744 \uc785\ub825\ud574\ubcf8 \uacb0\uacfc Integer \ubc94\uc704\ub97c \ub118\uc5b4\uc11c\ub294 \uac83\uc744 \uc54c \uc218 \uc788\uc5c8\ub2e4. long long\uc73c\ub85c \ubc14\uafe8\ub294\ub370\ub3c4 \uc2e4\ud328.. \uac12\uc774 \ub9e4\uc6b0 \ud06c\ub2e4\uace0 \ub290\ub080 \ub098\ub294 Java\uc758 BigInteger\ub97c \uc0ac\uc6a9\ud558\uc5ec \uad6c\ud604\ud558\ub294 \uac83\uc73c\ub85c \ubc29\ud5a5\uc744 \ubc14\uafb8\uc5c8\ub2e4.<\/p>\n<p>&nbsp;\uc774 \ubb38\uc81c\uc758 \uc810\ud654\uc2dd\uc740 \uc544\ub798\uc640 \uac19\ub2e4.<br \/>\n&nbsp; f(1) = 2<br \/>\n&nbsp; f(2) = 5<br \/>\n&nbsp; f(3) = 13<br \/>\n&nbsp; f(n) = 2 * f(n-1) + f(n-2) + f(n-3)<\/p>\n<p>&nbsp;<\/p>\n<div class=\"txc-textbox\" style=\"border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(238, 238, 238); border-right-color: rgb(238, 238, 238); border-bottom-color: rgb(238, 238, 238); border-left-color: rgb(238, 238, 238); background-color: rgb(238, 238, 238); padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; \">\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \">\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \">import java.math.BigInteger;<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \">import java.util.Scanner;<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \">\n<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \">public class Main {<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t<\/span>static BigInteger[] Data = new BigInteger[1002];<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t<\/span>public static void main(String[] args) {<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>Scanner scan = new Scanner(System.in);<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>Data[1] = new BigInteger(&#8220;2&#8221;);<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>Data[2] = new BigInteger(&#8220;5&#8221;);<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>Data[3] = new BigInteger(&#8220;13&#8221;);<span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>while (scan.hasNext())<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>{<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span>int n = scan.nextInt();<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span>if (n &gt; 3)<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span>{<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t<\/span>for (int i = 4; i&lt;=n; i++)<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t<\/span>{<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t\t<\/span>if (Data[i] != null)<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t\t\t<\/span>continue;<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t\t<\/span>Data[i] = Data[i-1].shiftLeft(1).add(Data[i-2]).add(Data[i-3]);<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t\t<\/span>}<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span>}<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span>System.out.println(Data[n]);<span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t\t<\/span><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t\t<\/span>}<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \"><span class=\"Apple-tab-span\" style=\"white-space:pre\">\t<\/span>}<\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \">}<\/p>\n<div>\n\n<\/div>\n<\/p>\n<\/div>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ucc98\uc74c\uc5d0 C\uc5b8\uc5b4\ub85c \uc9f0\uc73c\ub098 1000\uc744 \uc785\ub825\ud574\ubcf8 \uacb0\uacfc Integer \ubc94\uc704\ub97c \ub118\uc5b4\uc11c\ub294 \uac83\uc744 \uc54c \uc218 \uc788\uc5c8\ub2e4. long long\uc73c\ub85c \ubc14\uafe8\ub294\ub370\ub3c4 \uc2e4\ud328.. \uac12\uc774<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[74],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-algorithm"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8gT1J-W","_links":{"self":[{"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":1,"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":87,"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions\/87"}],"wp:attachment":[{"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jinukbaek.com\/blog\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}