• P4345 [SHOI2015]超能粒子炮·改


    题意

    • (displaystyle sum_{i=0}^k {n choose i} mod 2333)

    直接推式子:

    (p=2333,k=tp+r)

    [displaystyle sum_{i=0}^k {n choose i} \ = sum_{i=0}^{tp+r} {n choose i} \ =sum_{i=0}^{tp-1} {n choose i} + sum_{i=0}^{r} {n choose {tp+i}} \ =sum_{i=0}^{tp-1} {frac n p choose frac i p} {n \% p choose i \% p} + sum_{i=0}^{r} {frac n p choose t} {n \% p choose i} \ ]

    [=sum_{i=0}^{tp-1} {frac n p choose frac i p} {n \% p choose i \% p} + {frac n p choose t}sum_{i=0}^{r} {n \% p choose i} \ = sum_{i=0}^{p-1} {n \% p choose i} sum_{j=0}^{t-1} {frac n p choose j} + {frac n p choose t} sum_{i=0}^{r} {n \% p choose i} \ = 2^{n \% p} sum_{i=0}^{t-1} {frac n p choose i} + {frac n p choose t} sum_{i=0}^{r} {n \% p choose i} \ ]

    那么令(displaystyle S(n,k) = sum_{i=0}^k {n choose i}),就可以得到:

    [S(n,k)=2^{n \% p} cdot S(frac n p, frac k p -1) + {frac n p choose i} cdot S(n \% p,k \% r) ]

    递归求解即可

    #include<bits/stdc++.h>
    #define For(i, a, b) for(int i = (a), en = (b); i <= en; ++i)
    #define Rof(i, a, b) for(int i = (a), en = (b); i >= en; --i)
    #define Tra(u, i) for(int i = hd[u]; ~i; i = e[i].net)
    #define cst const
    #define LL long long
    #define DD double
    #define LD long double
    #define pb push_back
    #define mp make_pair
    #define fir first
    #define sec second
    #define inf 0x3f3f3f3f
    #define Inf 0x3f3f3f3f3f3f3f3f
    #define eps 1e-12
    #define mod 2333
    using namespace std;
    
    int t, fac[mod + 5], ifac[mod + 5];
    LL n, k;
    
    template <class T>
    void read(T &x){
    	char ch;
    	bool ok;
    	for(ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if(ch == '-') ok = 1;
    	for(x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    	if(ok) x = -x;
    }
    
    int fp(int x, int y){
    	int asi = 1;
    	while(y){
    		if(y & 1) asi = 1ll * asi * x % mod;
    		x = 1ll * x * x % mod;
    		y >>= 1;
    	}
    	return asi;
    }
    
    int c(int x, int y){return x < y ? 0 : 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;}
    int luc(LL x, LL y){
    	if(!y) return 1;
    	if(!x) return 0;
    	return 1ll * c(x % mod, y % mod) * luc(x / mod, y / mod) % mod;
    }
    
    int f[mod + 5][mod + 5];
    map<LL, map<LL, int> > ma;
    int get_s(LL x, LL y){
    	if(y < 0) return 0;
    	if(x < mod && y < mod) return f[x][y];
    	if(ma[x][y]) return ma[x][y] - 1;
    	int asi = 1ll * luc(x / mod, y / mod) * get_s(x % mod, y % mod) % mod;
    	asi = (asi + 1ll * fp(2, x % mod) * get_s(x / mod, y / mod - 1) % mod) % mod;
    	ma[x][y] = asi + 1;
    	return asi;
    }
    
    int main(){
    	//freopen("in", "r", stdin);
    	//freopen("c.out", "w", stdout);
    	fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
    	For(i, 2, mod - 1) fac[i] = 1ll * fac[i - 1] * i % mod;
    	ifac[mod - 1] = fp(fac[mod - 1], mod - 2);
    	Rof(i, mod - 2, 2) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
    	For(i, 0, mod) For(j, 0, mod)
    		f[i][j] = (1ll * f[i][j] + (j ? f[i][j - 1] : 0) + c(i, j)) % mod;
    	read(t);
    	while(t--){
    		read(n); read(k);
    		printf("%d
    ", get_s(n, k));
    	}
    	return 0;
    }
    
  • 相关阅读:
    CRoss IndustryStandard Process- for Data Mining 跨行业数据挖掘标准流程(中)
    CRoss IndustryStandard Process- for Data Mining 跨行业数据挖掘标准流程(上)
    window下安装pip工具,再利用pip安装工具来安装其他的python包
    采用ubuntu系统来安装tensorflow
    eclipse中添加python开发环境
    分类器的评价指标
    HBase的基本架构及其原理介绍
    快速排序的递归方式和非递归方式
    DeepCTR专题:DeepFM论文学习和实现及感悟
    DeepCTR专题:Neural Factorization Machines 论文学习和实现及感悟
  • 原文地址:https://www.cnblogs.com/lprdsb/p/13922635.html
Copyright © 2020-2023  润新知