UVALive
来源:互联网 发布:java页面跳转代码 编辑:程序博客网 时间:2024/06/05 14:46
传送门
#include<stdio.h>#include<bits/stdc++.h>#define ll long long#define pii pair<int,int>#define pll pair<ll,ll>#define MEM(a,x) memset(a,x,sizeof(a))#define lowbit(x) ((x)&-(x))using namespace std;const int inf=1e9+7;const int N = 1e6+5;const int M = 5e5;ll qPow(ll a,ll n){ ll ans=1; ll t=a%inf; while(n){ if(n&1){ ans=(ans*t)%inf; } t=(t*t)%inf; n>>=1; } return ans;}ll ny(ll a){//逆元 return qPow(a,inf-2);}ll fact[N];void initFact(){ fact[0]=1; for(int i=1;i<N;++i){ fact[i]=((ll)i*fact[i-1])%inf; }}ll C(int n,int k){ if(k>n){ return 0; } ll fz=fact[n]; ll fm=(fact[k]*fact[n-k])%inf; fm=ny(fm); return (fz*fm)%inf;}ll Cb(int n,int k){ if(k>n){ return 0; } ll ans=1; for(int i=0;i<k;++i){ ans=(ans*(n-i))%inf; } ll fm=fact[k]; fm=ny(fm); return (ans*fm)%inf;}ll f(ll k,int n){ ll t=(k*qPow(k-1,n-1))%inf; return t;}ll slove(int n,int m,int k){ ll ans=f(k,n); int flag=-1; for(int i=1;i<k;++i){ ll t=(C(k,k-i)*f(k-i,n))%inf; ans=(ans+flag*t)%inf; flag*=-1; } return ((ans*Cb(m,k))%inf+inf)%inf;}int main(){ //freopen("/home/lu/code/r.txt","r",stdin); //freopen("/home/lu/code/w.txt","w",stdout); int T; initFact(); scanf("%d",&T); for(int tt=1;tt<=T;++tt){ int n,m,k; scanf("%d%d%d",&n,&m,&k); ll ans=slove(n,m,k); printf("Case #%d: %lld\n",tt,ans); } return 0;}
阅读全文
0 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 二分图最大匹配翻车记
- HDU5768:Lucky7(中国剩余定理 & 容斥)
- 属性动画
- HihoCoder 1424Asa's Chess Problem
- 上机一 F AlvinZH的儿时梦想——木匠篇
- UVALive
- Android自定义进度条(用画笔手动画出来)
- EJB学习总结
- 多线程学习
- 小学期 BlueSky学长与友人帐
- tomcat7安装配置
- JSP的内置对象
- STM32添加路径报错
- 比较(关系)运算符