zoukankan      html  css  js  c++  java
  • 洛谷 P1313 计算系数 (二项式定理)

    这道题正好复习了二项式定理

    所以答案就是a^n * b^m * c(n, k)

    然后注意一些细节
    我一开始写组合数只写一行的组合数
    即c[0] = 1; c[i] = c[i-1] * (n - i + 1) / i
    但是因为要去模,同时式子里面有除法,所以不能用这种方式
    必须从头来推
    然后注意组合数推要从0开始

    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #define REP(i, a, b) for(int i = (a); i < (b); i++)
    #define _for(i, a, b) for(int i = (a); i <= (b); i++)
    using namespace std;
    
    const int MAXN = 1e4 + 10;
    const int MOD = 10007;
    int c[MAXN][MAXN];
    
    int pow(int a, int b)
    {
    	int res = 1 % MOD; a %= MOD;
    	for(; b; b >>= 1)
    	{
    		if(b & 1) res = (res * a) % MOD;
    		a = (a * a) % MOD;
    	}
    	return res;
    }
    
    int main()
    {
    	int a, b, k, n, m;
    	scanf("%d%d%d%d%d", &a, &b, &k, &n, &m);
       	_for(i, 0, k)
       	{
       		c[i][0] = 1;
    		_for(j, 1, i)
    			c[i][j] = (c[i-1][j] + c[i-1][j-1]) % MOD;	
    	}
    	printf("%d
    ", ((pow(a, n) * pow(b, m)) % MOD) * c[k][n] % MOD);
        return 0;
    }
  • 相关阅读:
    Restful风格
    SpringMVC概念、原理及搭建
    Mybatis搭建
    HttpServletRequest、HttpServletResponse、Cookie、Session
    Servlet基础
    Spring整合Mybatis
    PHP代码标识
    IOC及Bean容器
    框架
    Spring概况
  • 原文地址:https://www.cnblogs.com/sugewud/p/9819338.html
Copyright © 2011-2022 走看看