[bzoj4591] [Shoi2015]超能粒子炮·改

來源:互聯網
上載者:User

標籤:

  公式恐懼症患者膜了半天題解QAQ

  具體過程見網上其他題解吧>_<

 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #define ll long long 6 #define MOD(x) x-=x>=modd?modd:0 7 using namespace std; 8 const int modd=2333; 9 int c[modd][modd],sum[modd][modd];10 ll n,k;11  12  13  14 inline int lucas(ll a,ll b){15     if(a<b)return 0;16     if(a<modd&&b<modd)return c[a][b];17     return c[a%modd][b%modd]*lucas(a/modd,b/modd)%modd;18 }19 int calc(ll n,ll k){20     if(k<0)return 0;21     return (calc(n/modd,k/modd-1)*sum[n%modd][2332]+lucas(n/modd,k/modd)*sum[n%modd][k%modd])%modd;22 }23 inline void prerun(){24     register int i,j;25     for(i=0;i<modd;i++)c[i][0]=sum[i][0]=sum[0][i]=1;26     for(i=1;i<modd;i++)27         for(j=1;j<=i;j++)28             c[i][j]=c[i-1][j]+c[i-1][j-1],MOD(c[i][j]),29             sum[i][j]=sum[i][j-1]+c[i][j],MOD(sum[i][j]);30     for(i=1;i<modd;i++)for(j=i+1;j<modd;j++)sum[i][j]=sum[i][j-1];31 }32 int main(){33     prerun();int T;34     for(scanf("%d",&T);T;T--)35         scanf("%lld%lld",&n,&k),printf("%d\n",calc(n,k));36 }37 
View Code

 

[bzoj4591] [Shoi2015]超能粒子炮·改

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.