日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu3037 Saving Beans

發布時間:2025/4/16 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu3037 Saving Beans 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意: ?給了n課不同的樹,要求將 0,1,2,3,4,5,...m個松果,分別放在n棵樹上的方案數有多少
? ? 總結:當選取得數含有0時,要轉化,然而開始并不會組合數學太爛了

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <map> //#define IO ios::sync_with_stdio(false),cin.tie(0), cout.tie(0); //#pragma comment(linker, "/STACK:1024000000,1024000000") void ex_gcd(int a, int b, int &d, int &x, int &y) { if (!b) { x = 1; y = 0; d = a; } else { ex_gcd(b, a%b, d, y, x); y -= x * (a / b); }; } int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } int lcm(int a,int b){return a/gcd(a,b)*b;} int inv_exgcd(int a, int m) { int d, x, y;ex_gcd(a, m, d, x, y);return d == 1 ? (x + m) % m : -1; } typedef long long ll; const int maxn=1e6; using namespace std; ll fac[maxn]; ll a,b,mod; void init() {fac[0]=1;for(int i=1;i<=mod;++i)fac[i]=fac[i-1]*i%mod; } ll C(ll n,ll m,ll mod) {if(m>n)return 0;ll ans=fac[n];ans*=inv_exgcd((fac[m]*fac[n-m])%mod,mod);return ans%mod; } ll Lucas(ll n,ll m,ll mod) {if(m==0)return 1;return C(n%mod,m%mod,mod)*Lucas(n/mod,m/mod,mod)%mod; } int main() {ll t;scanf("%lld",&t);while(t--){scanf("%lld%lld%lld",&a,&b,&mod);init();ll lu=Lucas(1+b,a,mod);printf("%lld\n",lu);}return 0; } //waw: ///https://blog.csdn.net/sdfzchy/article/details/76099080 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <map> //#define IO ios::sync_with_stdio(false),cin.tie(0), cout.tie(0); //#pragma comment(linker, "/STACK:1024000000,1024000000") void ex_gcd(int a, int b, int &d, int &x, int &y) { if (!b) { x = 1; y = 0; d = a; } else { ex_gcd(b, a%b, d, y, x); y -= x * (a / b); }; } int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } int lcm(int a,int b){return a/gcd(a,b)*b;}//?è3yoó3?·àò?3? int inv_exgcd(int a, int m) { int d, x, y;ex_gcd(a, m, d, x, y);return d == 1 ? (x + m) % m : -1; } typedef long long ll; const int maxn=1e4+10; using namespace std; int primer[maxn]; ll fac[maxn][maxn]; ll inv[maxn][maxn]; ll a[maxn]; ll n,m,mod,cnt=0; void isprime() {for(int i=2;i<maxn;++i){if(!a[i]){ primer[cnt++]=i;for(int j=2*i;j<=maxn;j+=i)a[j]=1;}} } void init()//預處理階乘和逆元 {for(int i=0;i<cnt;++i){fac[primer[i]][0]=inv[primer[i]][0]=1;for(int j=1;j<primer[i];++j){fac[primer[i]][j] = (fac[primer[i]][j-1] * j) % primer[i];inv[primer[i]][j] = inv_exgcd(fac[primer[i]][j],primer[i]);}} } ll C(ll n,ll m,ll mod) {if(m>n)return 0;if(n==m)return 1;return fac[mod][n]*(inv[mod][m]*inv[mod][n-m]%mod)%mod;//ll ans=fac[n]*inv_exgcd((fac[m]*fac[n-m])%mod,mod); return ans%mod; } ll Lucas(ll n,ll m,ll mod) {if(m==0)return 1;return C(n%mod,m%mod,mod)*Lucas(n/mod,m/mod,mod)%mod; } int main() {isprime();init();ll t;scanf("%lld",&t);while(t--){scanf("%lld%lld%lld",&n,&m,&mod);ll lu=Lucas(1+m,n,mod);printf("%lld\n",lu);}return 0; }

?

總結

以上是生活随笔為你收集整理的hdu3037 Saving Beans的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。