https://codeforces.com/contest/1549/problem/E
题目大意自己悟吧,不解释了。
这题在赛时我想的是fft,但是题解说不用fft就能求出多项式的系数,fft在这题时间复杂度有点高。
使用多项式长除法就能求出系数,k^x的系数就是抓x个pig 的答案。
求出此多项式。(这题dp也能做)
代码参考题解:https://codeforces.com/blog/entry/92335
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <complex>
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(a) ((a)&-(a))
#define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define fi first
#define sc second
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const ll mod1=1e9+9;
const ll N =6e6+10;
const ll M=2e6+10;
const double eps = 1e-6;
const double PI=acos(-1);ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll re(){ll x;scanf("%lld",&x);return x;}
int dx[8]= {1,0,-1,0,1,1,-1,-1}, dy[8] = {0,1,0,-1,1,-1,1,-1};
ll qk(ll a,ll b){ll ans=1;while(b){if(b&1) ans=ans*a%mod;a=a*a%mod;b/=2;}return ans;}
int m,n;
struct Combo {vector<ll> facs;vector<ll> invfacs;int N;Combo(int N) {this->N=N;facs.assign(N+1,0);invfacs.assign(N+1,0);facs[0] = 1;for (int i = 1; i <= N; i++) {facs[i] = (facs[i-1]*i)%mod;}invfacs[N] = qk(facs[N],mod-2);for (int i = N-1; i >= 0; i--) {invfacs[i] = (invfacs[i+1]*(i+1))%mod;}}ll C(int n, int k) {if (n<0||k<0||n<k) return 0LL;ll denInv = (invfacs[k]*invfacs[n-k])%mod;ll ans = (facs[n]*denInv)%mod;return ans;}
};
void solve(){cin>>n;m=3*n+3;Combo c(m);vector<ll> num(m+1,0);for(int i=1;i<=m;i++){num[i]=c.C(m,i);if(i<=3){num[i]-=c.C(3,i);num[i]=(num[i]+mod)%mod;}}vector<ll> p(m,0);for(int i=3*n;i>=0;--i){p[i]=num[i+3];num[i+2]=(num[i+2]-3*p[i]+3*mod)%mod;num[i+1]=(num[i+1]-3*p[i]+3*mod)%mod;}int q;cin>>q;for(int i=1;i<=q;i++){int x;cin>>x;cout<<p[x]<<endl;}
}int main()
{iosint t=1;// cin>>t;// t=re();while(t--) solve();return 0;
}