{"id":1445,"date":"2013-04-03T02:08:56","date_gmt":"2013-04-02T18:08:56","guid":{"rendered":"https:\/\/blog.rexdf.org\/?p=1445"},"modified":"2013-04-03T02:08:56","modified_gmt":"2013-04-02T18:08:56","slug":"codeforces-177-d","status":"publish","type":"post","link":"https:\/\/blog.rexdf.org\/ja\/2013\/04\/codeforces-177-d\/","title":{"rendered":"Codeforces 177 D"},"content":{"rendered":"<div>\n<div>Polo the Penguin and Houses<\/div>\n<div>\n<div>time limit per test<\/div>\n<p>2 seconds<\/p><\/div>\n<div>\n<div>memory limit per test<\/div>\n<p>256 megabytes<\/p><\/div>\n<div>\n<div>input<\/div>\n<p>standard input<\/p><\/div>\n<div>\n<div>output<\/div>\n<p>standard output<\/p><\/div>\n<\/div>\n<div>\n<p>Little penguin Polo loves his home village. The village has\u00a0<i>n<\/i>\u00a0houses, indexed by integers from 1 to\u00a0<i>n<\/i>. Each house has a plaque containing an integer, the\u00a0<i>i<\/i>-th house has a plaque containing integer\u00a0<i>p<\/i><sub><i>i<\/i><\/sub>\u00a0(1\u2009\u2264\u2009<i>p<\/i><sub><i>i<\/i><\/sub>\u2009\u2264\u2009<i>n<\/i>).<\/p>\n<p>Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number\u00a0<i>x<\/i>. Then he goes to the house whose number is written on the plaque of house\u00a0<i>x<\/i>\u00a0(that is, to house\u00a0<i>p<\/i><sub><i>x<\/i><\/sub>), then he goes to the house whose number is written on the plaque of house\u00a0<i>p<\/i><sub><i>x<\/i><\/sub>\u00a0(that is, to house\u00a0<i>p<\/i><sub><i>p<\/i><sub><i>x<\/i><\/sub><\/sub>), and so on.<\/p>\n<p>We know that:<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li>When the penguin starts walking from any house indexed from 1 to\u00a0<i>k<\/i>, inclusive, he can walk to house number 1.<\/li>\n<li>When the penguin starts walking from any house indexed from\u00a0<i>k<\/i>\u2009+\u20091\u00a0to\u00a0<i>n<\/i>, inclusive, he definitely cannot walk to house number 1.<\/li>\n<li>When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>You need to find the number of ways you may write the numbers on the houses&#8217; plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by\u00a01000000007\u00a0(10<sup>9<\/sup>\u2009+\u20097).<\/p>\n<\/div>\n<div>\n<div>Input<\/div>\n<p>The single line contains two space-separated integers\u00a0<i>n<\/i>\u00a0and\u00a0<i>k<\/i>\u00a0(1\u2009\u2264\u2009<i>n<\/i>\u2009\u2264\u20091000,\u20091\u2009\u2264\u2009<i>k<\/i>\u2009\u2264\u2009<i>min<\/i>(8,\u2009<i>n<\/i>)) \u2014 the number of the houses and the number\u00a0<i>k<\/i>\u00a0from the statement.<\/p>\n<\/div>\n<div>\n<div>Output<\/div>\n<p>In a single line print a single integer \u2014 the answer to the problem modulo\u00a01000000007\u00a0(10<sup>9<\/sup>\u2009+\u20097).<\/p>\n<\/div>\n<div>\n<div>Sample test(s)<\/div>\n<div>\n<div>\n<div>input<\/div>\n<pre>5 2<\/pre>\n<\/div>\n<div>\n<div>output<\/div>\n<pre>54<\/pre>\n<\/div>\n<div>\n<div>input<\/div>\n<pre>7 4<\/pre>\n<\/div>\n<div>\n<div>output<\/div>\n<pre>1728<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"brush: actionscript3; gutter: true\">\r\n#include &lt;iostream&gt;\r\n\r\nusing namespace std;\r\n\r\nconst long long MOD=1e9+7;\r\n\r\nlong long pow_mod(int n,int k)\r\n{\r\n    long  long ret=1,p=n;\r\n    while(k)\r\n    {\r\n        if(k&amp;1)\r\n        {\r\n            ret*=p;\r\n            ret%=MOD;\r\n        }\r\n        p*=p;\r\n        p%=MOD;\r\n        k&gt;&gt;=1;\r\n    }\r\n    return ret;\r\n}\r\n\r\nint main()\r\n{\r\n    int N,K;\r\n    cin&gt;&gt;N&gt;&gt;K;\r\n    cout&lt;&lt;((pow_mod(K,K-1)*pow_mod(N-K,N-K))%MOD)&lt;&lt;endl;\r\n    return 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Polo the Penguin and Houses time limit p &hellip; <a href=\"https:\/\/blog.rexdf.org\/ja\/2013\/04\/codeforces-177-d\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[125],"class_list":["post-1445","post","type-post","status-publish","format-standard","hentry","category-algorithm","tag-codeforces"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/1445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/comments?post=1445"}],"version-history":[{"count":0,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/1445\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/media?parent=1445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/categories?post=1445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/tags?post=1445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}