Codeforces Round #177 (Div. 1) B. Polo the Penguin and Houses【组合数学】

 

http://codeforces.com/contest/288/problem/B

ans = k^(k-1) * (n-K)^(n-k).

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
template <class T> void checkmin(T &t,T x) {if(x < t) t = x;}
template <class T> void checkmax(T &t,T x) {if(x > t) t = x;}
template <class T> void _checkmin(T &t,T x) {if(t==-1) t = x; if(x < t) t = x;}
template <class T> void _checkmax(T &t,T x) {if(t==-1) t = x; if(x > t) t = x;}
typedef pair <int,int> PII;
typedef pair <double,double> PDD;
typedef long long ll;
#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)
#define MOD 1000000007
ll n , k;
ll solve(ll a , ll b) {
    if(b == 0) return 1;
    if(b == 1) return a % MOD;
    ll t = 1;
    if(b % 2 == 1) t = a;
    ll tt = solve(a , b/2);
    return (((tt * tt) % MOD)*t) % MOD;
}
int main() {
    cin >> n >> k;
    ll ans = solve(n-k , n - k);
    ans *= solve(k,k-1);
    cout << ans % MOD << endl;
    return 0;
}

 

posted @ 2013-04-03 02:17  aiiYuu  阅读(251)  评论(0)    收藏  举报