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

题目:https://nanti.jisuanke.com/t/41412
思路:dfs
           先取ai>2  2^12>3000 因此至多取11个 其余用1补
           (3000*2)-(3000+2)=2998 那么需要加入2998个1 正好3000位 所以 3000是ai最大取值
           计算ans时 有重复元素的排列组合 :如1112233 res=7!/(3!*2!*2!)
           另外预处理阶乘及其逆元

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll fac[3001];//阶乘
ll infac[3001];//逆元
ll ans[3001];
ll a[3001];//数列
int v[3001];// i在数组中的个数
ll qPow(ll n,int a)
{
    ll res=1;
    while(a)
    {
        if(a&1) res=res*n%mod;
        n=n*n%mod;
        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;
    ans[cnt]=(ans[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,mul-sum+cnt);
        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;
}

原文地址:https://www.cnblogs.com/c4Lnn/p/12090704.html

时间: 2024-08-30 09:43:28

The Preliminary Contest for ICPC Asia Shanghai 2019 D. Counting Sequences I的相关文章

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)

The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/t/41400 题意: 给你三个数组a,b,c,要你求有多少个三元组(i,j,k),使得 \[ \begin{array}{l}{\left|A_{i}-B_{j}\right| \leq C_{k}, \text { and }} \\ {\left|B_{j}-C_{k}\right| \leq

The Preliminary Contest for ICPC Asia Shanghai 2019

D. Counting Sequences I 暴力搜索. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; map<vector<short>, short> m; vector<short> vec; void calc(int num1) { vector<short> tmp; if(num1) t

Digit sum-----The Preliminary Contest for ICPC Asia Shanghai 2019

A digit sum S_b(n)Sb?(n) is a sum of the base-bb digits of nn. Such as S_{10}(233) = 2 + 3 + 3 = 8S10?(233)=2+3+3=8, S_{2}(8)=1 + 0 + 0 = 1S2?(8)=1+0+0=1, S_{2}(7)=1 + 1 + 1 = 3S2?(7)=1+1+1=3. Given NN and bb, you need to calculate \sum_{n=1}^{N} S_b

The Preliminary Contest for ICPC Asia Shanghai 2019 G. Substring (滑窗+哈希)

G. Substring 哎 一直超时or超内存 然后一直改一直改 然后 是 答案错误 然后 然后 最后结论是哈希姿势不对 我在别的地方找了这个: //https://www.cnblogs.com/napoleon_liu/archive/2010/12/29/1920839.html uint32_t hash( uint32_t a) { a = (a+0x7ed55d16) + (a<<12); a = (a^0xc761c23c) ^ (a>>19); a = (a+0x

01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019

题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: 从最大重量的石子开始背包,每次ans+=dp[j-v[i]]就行了. 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include &

给定进制下1-n每一位数的共享(Digit sum)The Preliminary Contest for ICPC Asia Shanghai 2019

题意:https://nanti.jisuanke.com/t/41422 对每一位进行找循环节规律就行了. 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <io

The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum

题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; int dp[11][1000001]={0}; int main() { for(int i=2;i<=10;i++) { for(int j=1;j<=1000000;j++) { int t=j; int res=0; res=j%i; dp[i][j]=res+dp[i][j/i]+dp[i][j

The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs

题目:https://nanti.jisuanke.com/t/41399 思路:差分数组 区间内操作次数为奇数次则灯为打开状态 #include<bits/stdc++.h> using namespace std; map<int,int>mp; int main() { int T; scanf("%d",&T); int n,m; int l,r; for(int i=1;i<=T;i++) { mp.clear(); scanf(&quo

The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game

题目:https://nanti.jisuanke.com/t/41420 思路:当a(a∈S′)为最小值 如果Sum(S′)−a≤Sum(S−S′)成立 那么(∀t∈S′,Sum(S′)−t≤Sum(S−S′))恒成立            先算01背包方案数 再从小到大排序进行退背包 #include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int a[400]; int dp[150001]; int main()