POJ3734-EGF

POJ3734

题目描述

题目描述

题解

EGF.
显然红色和绿色的方案数为:
F ( x ) = ∑ i = 0 ∞ [ 2 ∣ n ] x i i ! = e x + e − x 2 F(x)=\sum\limits_{i=0}^{\infty}[2|n]\frac{x^i}{i!}=\frac{e^x+e^{-x}}{2}\\ F(x)=i=0[2n]i!xi=2ex+ex
而黄色和蓝色的方案数为:
G ( x ) = ∑ i = 0 ∞ x i i ! = e x G(x)=\sum\limits_{i=0}^{\infty}\frac{x^i}{i!}=e^x\\ G(x)=i=0i!xi=ex
将它们全部乘起来,即可得到答案的生成函数:
A n s ( x ) = e 4 x + 2 e 2 x + 1 4 Ans(x)=\frac{e^{4x}+2e^{2x}+1}{4} Ans(x)=4e4x+2e2x+1
考虑转换成通项公式:
A n s ( x ) = 1 4 + 1 4 ∑ i = 0 ∞ 4 i x i i ! + 1 2 ∑ i = 0 ∞ 2 i x i i ! Ans(x)=\frac{1}{4}+\frac{1}{4}\sum\limits_{i=0}^{\infty}4^i\frac{x^i}{i!}+\frac{1}{2}\sum\limits_{i=0}^{\infty}2^i\frac{x^i}{i!} Ans(x)=41+41i=04ii!xi+21i=02ii!xi
常数项可忽略,由于是排列,还要乘上 n ! n! n!,那么 [ x n ] [x^n] [xn]即为:
n ! 4 n − 1 + 2 n − 1 n ! = 4 n − 1 + 2 n − 1 n!\frac{4^{n-1}+2^{n-1}}{n!}=4^{n-1}+2^{n-1}\\ n!n!4n1+2n1=4n1+2n1

代码

#include  <map>
#include  <set>
#include  <cmath>
#include  <queue>
#include  <cstdio>
#include  <vector>
#include  <climits>
#include  <cstring>
#include  <cstdlib>
#include  <iostream>
#include  <algorithm>
#define int long long
using namespace std;
const int mod=1e4+7; 
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}return ans;
}
int n,t;
signed main(){
	cin>>t;
	while(t--){
		cin>>n;
		cout<<(ksm(4,n-1)%mod+ksm(2,n-1)%mod)%mod<<endl;
	}return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值