码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-06-18 16:57:35      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

  公式恐惧症患者膜了半天题解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]超能粒子炮·改

标签:

原文地址:http://www.cnblogs.com/czllgzmzl/p/5596319.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!