The Preliminary Contest for ICPC Asia Shanghai 2019 D. Counting Sequences I

Title: https://nanti.jisuanke.com/t/41412
ideas: dfs
           first take ai> 2 2 ^ 12> 3000 11 thus taken up by the remaining complement 1
           (3000 * 2) - (3000 + 2) = 2998 then 1 just need to add 2998 3000 3000 so the maximum value ai is
           calculated permutations ans when repeating elements:!, such as 1112233 res = 7 / (3 * 2 * 2!!!)
           Further pretreatment and inverse factorial

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int mod=1e9+7;
FAC LL [ 3001 ]; // factorial 
LL infac [ 3001 ]; // inverse element 
LL ANS [ 3001 ];
A LL [ 3001 ]; // number of columns 
int V [ 3001 ]; // I number in the array 
LL qPow (n-LL, int A)
{
    ll res=1;
    while(a)
    {
        if(a&1) res=res*n%mod;
        N = n * n% v;
        a>>=1;
    }
    return res;
}
void calc(int cur,int cnt)
{
    for(int i=1;i<=cur;i++) v[a[i]]++;
    int res=fac[cnt];
    for(int i=1;i<=3000;i++) if(v[i]>1) res=res*infac[v[i]]%mod;
    years [cnt] = (years [cnt] + res)% mod;    
} 
void dfs(int cur,int start,int idx,ll mul,ll sum,ll cnt) 
{
    if(cur==0) 
    {
        memset(v,0,sizeof v);
        v [ 1 ] = mul- sum;
        calc (cnt, many -sum + ent);    
        return ;
    }
    for(int i=start;i<=3000;i++)
    {
        if(mul*i-sum-i>3000-cnt) return;
        a[idx]=i;
        dfs(cur-1,i,idx+1,mul*i,sum+i,cnt);
    }
}
int main ()
{
    memset(ans,0,sizeof ans);
    fac[0]=infac[0]=1;
    for(ll i=1;i<=3000;i++) fac[i]=fac[i-1]*i%mod,infac[i]=infac[i-1]*qPow(i,mod-2)%mod;
    for(int i=2;i<=11;i++) dfs(i,2,1,1,0,i);
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        printf("%d\n",ans[n]);
    } 
    return 0;
}
 

Guess you like

Origin www.cnblogs.com/c4Lnn/p/12090704.html
Recommended