牛客挑战赛37 牛牛与序列计数

LINK:牛牛与序列计数

很早以前打的一场比赛的题目 A题都不会写 当场自闭...

4个种球 其中两种球个数必须为奇数 两种球个数必须为偶数 问生成最后的序列的方案数有多少种。

当时啥都不会 考虑打表找规律 这个规律非常难找 可以放弃。

这道题是一道经典的计数模型。考虑EGF来解决。

显然对于奇数 (F(x)=frac{e^x-e^{-x}}{2}) 对于偶数 (G(x)=frac{e^x+e^{-x}}{2})

那么整个式子其实就为 ((frac{e^x-e^{-x}}{2})^2cdot (frac{e^x+e^{-x}}{2})^2)

简单的化简一下 可以发现等于(frac{e^{4x}+e^{-4x}-2}{16})

展开即可 发现-2和(x^0)的系数抵消掉 说明0个球的时候没有合法方案 所以当n不等于0的时候答案的系数为 (frac{4^n+(-4)^n}{16})

奇数的时候显然为0 偶数的时候(2^{2n-3})

这个规律找的话我觉得还是很难找到的。(EGF真香...

//#include<bitsstdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 999999999999999ll
#define ldb long double
#define pb push_back
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define put(x) printf("%d
",x)
#define putl(x) printf("%lld
",x)
#define gc(a) scanf("%s",a+1);
#define rep(p,n,i) for(RE ll i=p;i<=n;++i)
#define go(x) for(ll i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE ll i=n;i>=p;--i)
#define pii pair<ll,ll> 
#define F first
#define S second
#define mk make_pair
#define mod 1000000007
#define RE register
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define ull unsigned long long
#define P 1000000000000000ll
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
	return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline ll read()
{
	RE ll x=0,f=1;char ch=getc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
	return x*f;
}
ll n;
inline ll ksm(ll b,ll p)
{
	ll cnt=1;
	while(p)
	{
		if(p&1)cnt=cnt*b%mod;
		b=b*b%mod;p=p>>1;
	}
	return cnt;
}
int main()
{
	freopen("1.in","r",stdin);
	get(n);
	if(n&1){puts("0");return 0;}
	else putl(ksm(2,(2*n-3)%(mod-1)));
	return 0;
}

原文地址:https://www.cnblogs.com/chdy/p/12597519.html