您的位置:首页 > 其它

Wannafly挑战赛11_A_B_D

2018-03-13 20:34 441 查看
传送门

A.白兔的分身术

思路:看完题目第一反应p=n,k=1,直接交一发。提交过程中思考了一下,显然取p=n,k=1最优。

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
int main ()
{
//yyy_3y
//freopen("1.in","r",stdin);
LL n; scanf("%lld",&n);
printf("%lld\n",n+1);
return 0;
}


B.白兔的式子

思路:其实我发现手推也很容易推出(实在不行就打表233),

f
[m] = C(n-1,m-1)*an−mn−m*bm−1m−1;

接下来问题就转变为求这三项的值的乘积,后两项非常容易,快速幂就行,对于前面C(n-1,m-1),可以用到费马小定理求组合数(只需要将r!和(n-r)!用逆元的方法就可以解决)



#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
const LL mod =998244353;
using namespace std;
LL f
;
LL my_pow(LL a,LL b)
{
LL ans=1;
while(b){
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
LL inv(LL a,LL b)
{
return my_pow(a,b-2);
}
LL C(LL n,LL m)
{
return f
*inv(f[m],mod)%mod*inv(f[n-m],mod)%mod;
}
int main ()
{
//yyy_3y
//freopen("1.in","r",stdin);
f[0]=1;
for(int i=1;i<N;i++) f[i]=i*f[i-1]%mod;
int T; scanf("%d",&T);
for(int i=1;i<=T;i++){
int a,b,n,m; scanf("%d%d%d%d",&a,&b,&n,&m);
LL a1=my_pow(a,n-m);
LL b1=my_pow(b,m-1);
printf("%lld\n",C(n-1,m-1)*a1%mod*b1%mod);
}
return 0;

}


D—>bolg下一篇。

bc43
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Wannafly