本文共 1014 字,大约阅读时间需要 3 分钟。
ans = k^(k-1) * (n-K)^(n-k).
#include #include #include #include #include #include #include #include #include using namespace std;template void checkmin(T &t,T x) { if(x < t) t = x;}template void checkmax(T &t,T x) { if(x > t) t = x;}template void _checkmin(T &t,T x) { if(t==-1) t = x; if(x < t) t = x;}template void _checkmax(T &t,T x) { if(t==-1) t = x; if(x > t) t = x;}typedef pair PII;typedef pair PDD;typedef long long ll;#define foreach(it,v) for(__typeof((v).begin()) it = (v).begin(); it != (v).end ; it ++)#define MOD 1000000007ll 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;}
转载于:https://www.cnblogs.com/aiiYuu/archive/2013/04/03/2997144.html