2 条题解
-
1aph。 (chenqianrong) LV 7 @ 2021-08-22 17:11:20
#include<bits/stdc++.h> using namespace std; long long f[1005][1005]; int main() { int a,b,k,n,m; cin>>a>>b>>k>>n>>m; f[0][0]=1; for (int i=0; i<=n; i++){ for (int j=0; j<=m; j++){ if (i==0 && j==0) continue; f[i][j]=0; if (i>0) f[i][j]=(f[i][j]+f[i-1][j]*a)%10007; if (j>0) f[i][j]=(f[i][j]+f[i][j-1]*b)%10007; } } cout<<f[n][m]; return 0; }
-
-12019-04-21 11:04:51@
这里用不用逆元都可以,这里提供一个使用逆元的版本。
/* */ #define method_1 #ifdef method_1 /* */ #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<set> #include<map> #include<queue> #include<stack> #include<vector> #include<cstring> #include<cstdlib> #include<iomanip> #define D(x) cout<<#x<<" = "<<x<<" " #define E cout<<endl using namespace std; typedef long long ll; typedef pair<int,int>pii; const int maxn=1000+5; const int mod=10007; const int INF=0x3f3f3f3f; ll a,b,k,n,m; ll ksm(ll a,ll b){ ll ans=1%mod; while(b){ if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } ll jc_inv[maxn],jc[maxn]; void pre(int n){ ll ans=1; for(ll i=1;i<=n;i++){ ans*=i; ans%=mod; jc[i]=ans; jc_inv[i]=ksm(ans,mod-2); } } ll cal(ll k,ll n){ ll ans=1%mod; ans=jc[k]*jc_inv[n]*jc_inv[k-n]%mod; /* for(ll i=1;i<=k;i++){ ans*=i; ans%=mod; } for(ll i=1;i<=n;i++){ ans*=jc_inv[i]; ans%=mod; } for(ll i=1;i<=k-n;i++){ ans*=jc_inv[i]; ans%=mod; } */ return ans; } int main() { ios::sync_with_stdio(false); // freopen("计算系数.in","r",stdin); cin>>a>>b>>k>>n>>m; pre(k); ll ans=1; ans*=ksm(a,n)*ksm(b,m); ans%=mod; // cout<<ans<<endl; cout<<ans*cal(k,n)%mod; return 0; } #endif #ifdef method_2 /* */ #endif #ifdef method_3 /* */ #endif
- 1