• CSP.ac #61乘积求和


    题面大意:

    #61乘积求和
    如果看不了请登入,如果还看不了就是你没去qbxt

    solution

    帕斯卡法则:

    (dbinom{n - 1}{k} + dbinom{n - 1}{k - 1} = dbinom{n}{k})

    证明

    (dbinom{n}{k})是从(n)中选(k)个,有多少种组合
    (n)个数中拿出一个数(x),有两种情况
    (1.)(x)的话,那就为(dbinom{n - 1}{k - 1})
    (2.)不选(x)的话,那就为(dbinom{n}{k - 1})
    两者加和就为(dbinom{n}{k})

    二项式定理

    对于一个二项式,((a+b)^n=sumlimits_{k = 0}^{n}dbinom{n}{k}a^{n - k}b^k)

    证明1:

    由数学归纳法,当(n=1),左边(=a+b),右边(=dbinom{0}{1}a+dbinom{1}{1}b)
    (n=k)时该式成立,则(n=k+1)时,
    (=(a+b)^n∗(a+b))
    (=a∗sumlimits_{k = 0}^{ n}dbinom{n}{k}a^{n - k}b^k+b∗sumlimits_{j = 0}^{ n}dbinom{n}{j}a^{n - j}b^j)
    (=sumlimits_{k = 0}^{n}dbinom{n}{k}a^{n - k + 1}b^k+sumlimits_{j = 0}^{n}dbinom{n}{j}a^{n - j}b^{j + 1})
    (=a^{n + 1}sumlimits_{k = 1}^{n}dbinom{n}{k}a^{n - k + 1}b^k+sumlimits_{j = 0}^{n}dbinom{n}{j}a^{n - j}b^{j + 1})(把(k = 0)单独取出来)
    (=a^{n + 1}+sumlimits_{k = 1}^{n}dbinom{n}{k}a^{n - k + 1}b^k+sumlimits_{k = 1}^{n + 1}dbinom{n}{k - 1}a^{n - k + 1}b^{k})(令(j = k - 1))
    (=a^{n + 1}+sumlimits_{k = 1}^{n}dbinom{n}{k}a^{n - k + 1}b^k+b^{n + 1}+sumlimits_{k = 1}^{n}dbinom{n}{k - 1}a^{n - k + 1}b^{k})(取出第(k = n + 1)项)
    (=a^{n + 1}+b^{n + 1}+sumlimits_{k = 1}^{n}left(dbinom{n}{k} + dbinom{n}{k - 1} ight)a^{n - k + 1}b^{k})(加和)
    (=a^{n + 1}+b^{n + 1}+sumlimits_{k = 1}^{n}dbinom{n + 1}{k}a^{n - k + 1}b^{k})(套用帕卡斯定理)
    (=sumlimits_{k = 0}^{ n + 1}dbinom{n + 1}{k}a^{n - k + 1}b^{k + 1})(再把k = 0加回去)

    证明2:

    ((a+b)^n) 是由(n)((a+b))相乘,对于其中(a^k)中的这一项,我们肯定是从中选择了(k)(a)相乘,剩下的(b)相乘就是(b^{n−k}),这样的选法共有(dbinom{n}{k})个,因此该项为(dbinom{n}{k}a^{n - k}b^k) ,那么((a+b)^n=sumlimits_{k = 0}^{n}dbinom{n}{k}a^{n - k}b^k)
    来自Zsf大佬整理的数学组提供的详细证明2

    变形

    (a = 1) 时就变成了((1+b)^n=sumlimits_{k = 0}^{n}dbinom{n}{k}b^k),这里的(b)可以为一个式子,既(一会用得到)
    (left(1 + dfrac{1 + sqrt{5}}{2} ight)^n = sumlimits_{i = 0}^{n}dbinom{n}{i}left(dfrac{1 + sqrt{5}}{2} ight)^i)
    (left(1 + dfrac{1 - sqrt{5}}{2} ight)^n = sumlimits_{i = 0}^{n}dbinom{n}{i}left(dfrac{1 - sqrt{5}}{2} ight)^i)

    斐波那契通项公式

    (F_n = dfrac{1}{sqrt{5}}left(left(dfrac{1 + sqrt{5}}{2} ight)^n -left(dfrac{1 - sqrt{5}}{2} ight)^n ight))

    证明

    见百度百科

    题解:

    (sumlimits_{i = 0}^{n}dbinom{n}{i}F_i)
    (= sumlimits_{i = 0}^{n}dbinom{n}{i}dfrac{1}{sqrt{5}}left(left(dfrac{1 + sqrt{5}}{2} ight)^i -left(dfrac{1 - sqrt{5}}{2} ight)^i ight))
    (= dfrac{1}{sqrt{5}}sumlimits_{i = 0}^{n}dbinom{n}{i}left(left(dfrac{1 + sqrt{5}}{2} ight)^i -left(dfrac{1 - sqrt{5}}{2} ight)^i ight))
    (= dfrac{1}{sqrt{5}}sumlimits_{i = 0}^{n}dbinom{n}{i}left(dfrac{1 + sqrt{5}}{2} ight)^i -dfrac{1}{sqrt{5}}sumlimits_{i = 0}^{n}dbinom{n}{i}left(dfrac{1 - sqrt{5}}{2} ight)^i)
    这里的变形上面讲过了
    (= dfrac{1}{sqrt{5}}left(1 + dfrac{1 + sqrt{5}}{2} ight)^n -dfrac{1}{sqrt{5}}left(1 + dfrac{1 - sqrt{5}}{2} ight)^n)
    (= dfrac{1}{sqrt{5}}left(dfrac{3 + sqrt{5}}{2} ight)^n -dfrac{1}{sqrt{5}}left(dfrac{3 - sqrt{5}}{2} ight)^n)
    (= dfrac{1}{sqrt{5}}left(left(dfrac{3 + sqrt{5}}{2} ight)^n -left(dfrac{3 - sqrt{5}}{2} ight)^n ight))
    (= dfrac{1}{sqrt{5}}left(left(dfrac{6 + 2sqrt{5}}{4} ight)^n -left(dfrac{6 - 2sqrt{5}}{4} ight)^n ight))
    (= dfrac{1}{sqrt{5}}left(left(dfrac{1 + 2sqrt{5} + 5}{4} ight)^n -left(dfrac{1 - 2sqrt{5} + 5}{4} ight)^n ight))
    (= dfrac{1}{sqrt{5}}left(left({left(dfrac{1 + sqrt{5}}{2} ight)^2} ight)^n-left({left(dfrac{1 + sqrt{5}}{2} ight)^2} ight)^n ight))
    (= dfrac{1}{sqrt{5}}left(left(dfrac{1 + sqrt{5}}{2} ight)^{2n} - left(dfrac{1 - sqrt{5}}{2} ight)^{2n} ight))
    (= F_{2n})

    (Code)

    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    
    #define int long long
    #define rr register
    
    #define MAXN 2000010
    #define inf 1e9
    
    using namespace std;
    
    const int mod = 1e9 + 7;
    
    inline int read() {
    	int s = 0, f = 0;
    	char ch = getchar();
    	while (!isdigit(ch)) {f |= ch == '-'; ch = getchar();}
    	while (isdigit(ch)) {s = s * 10 + (ch ^ 48); ch = getchar();}
    	return f ? -s : s;
    }
    
    int T, n;
    
    int g[MAXN], inv[MAXN], f[MAXN];
    
    inline void init() {
    	f[0] = f[1] = 1;
    	g[0] = 1;
    	inv[0] = inv[1] = 1;
    	for (rr int i = 1; i <= 1000000; i++) 
    		g[i] = (i * g[i - 1]) % mod;
    	for (rr int i = 2; i <= 2000000; i++)
    		f[i] = (f[i - 1] + f[i - 2]) % mod;
    	for (rr int i = 2; i <= 1000000; i++) 
    		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    	for (rr int i = 2; i <= 1000000; i++)
    		inv[i] = (inv[i - 1] * inv[i]) % mod;
    }
    
    inline int C(int n, int m) {
        return (g[n] * inv[m] % mod) * inv[n - m] % mod;
    }
    
    signed main() {
    	init();
    	T = read();
    	while (T--) {
    		n = read();
    		cout << f[2 * n] << "
    ";
    	}
    }
    
  • 相关阅读:
    Linq与Lambda,神一般的工作效率
    svn和git孰优孰劣
    关于C++的***5的输出问题
    POJ 3469 Dual Core CPU(最小割)
    HDU 4259 Double Dealing
    最大流Dinic算法
    HDU 4442 Physical Examination(2012年金华赛区现场赛A题)
    int ,long , long long类型的范围
    POJ 1679 The Unique MST(判断最小生成树是否唯一)
    HDU 4280 Island Transport(网络流)
  • 原文地址:https://www.cnblogs.com/lieberdq/p/12792969.html
Copyright © 2020-2023  润新知