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;
;
ll fac[];//阶乘
ll infac[];//逆元
ll ans[];
ll a[];//数列
];// i在数组中的个数
ll qPow(ll n,int a)
{
ll res=;
while(a)
{
) res=res*n%mod;
n=n*n%mod;
a>>=;
}
return res;
}
void calc(int cur,int cnt)
{
;i<=cur;i++) v[a[i]]++;
int res=fac[cnt];
;i<=;i++) ) 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)
{
)
{
memset(v,,sizeof v);
v[]=mul-sum;
calc(cnt,mul-sum+cnt);
return;
}
;i++)
{
-cnt) return;
a[idx]=i;
dfs(cur-,i,idx+,mul*i,sum+i,cnt);
}
}
int main()
{
memset(ans,,sizeof ans);
fac[]=infac[]=;
;i<=;i++) fac[i]=fac[i-]*i%mod,infac[i]=infac[i-]*qPow(i,mod-)%mod;
;i<=;i++) dfs(i,,,,,i);
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%d\n",ans[n]);
}
;
}
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/ ...
- The Preliminary Contest for ICPC Asia Shanghai 2019
传送门 B. Light bulbs 题意: 起初\(n\)个位置状态为\(0\),\(m\)次操作,每次操作更换区间状态:\(0\)到\(1\),\(1\)到\(0\). 共有\(T,T\leq 1 ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 C. Triple
[传送门] FFT第三题! 其实就是要求有多少三元组满足两短边之和大于等于第三边. 考虑容斥,就是枚举最长边,另外两个数组里有多少对边之和比它小,然后就是 $n^3$ 减去这个答案. 当 $n \le ...
- 01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019
题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: ...
- 给定进制下1-n每一位数的共享(Digit sum)The Preliminary Contest for ICPC Asia Shanghai 2019
题意:https://nanti.jisuanke.com/t/41422 对每一位进行找循环节规律就行了. #define IOS ios_base::sync_with_stdio(0); cin ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 A. Lightning Routing I
传送门 因为某些原因,所以我就去学了 $LCT$ 维护直径, $LCT$ 维护直径我上一个博客讲得很详细了:传送门 这里维护虚儿子用的是 $multiset$ ,没写可删堆 #include<i ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum
题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...
- 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 ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs
题目:https://nanti.jisuanke.com/t/41399 思路:差分数组 区间内操作次数为奇数次则灯为打开状态 #include<bits/stdc++.h> using ...
随机推荐
- 在Opencv中将一幅图像均分成M* N个小图像
std::vector<std::vector<Mat> > partitionImage(Mat&src,int rows,int cols) 函数中有三个输入参数, ...
- 【ABAP系列】SAP ABAP OOALV 动态设置单元格可否编辑
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP OOALV 动 ...
- python2.X与3.X比较及Python编译器选择
- mysql——多表——合并查询结果
合并查询结果 合并查询结果 是将多个select语句的查询结果合并到一起 union关键字,数据库会将所有的查询结果合并到一起,然后除掉相同的记录: union all关键字,只是简单的合并到一起 前 ...
- Python 爬取SeeBug poc
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-08-24 21:42:52 # @Author : EnderZhou (z ...
- HDU 2973 YAPTCHA (威尔逊定理)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- etcd租约机制
新建租约 新建一个过期时间为120s的租约 # etcdctl lease grant lease 018f6d7bb11aba0d granted with TTL(120s) 查看新建的租约信息 ...
- [Python3] 031 常用模块 shutil & zipfile
目录 shutil 1. shutil.copy() 2. shutil.copy2() 3. shutil.copyfile() 4. shutil.move() 5. 归档 5.1 shutil. ...
- 【Linux 网络编程】OSI七层模型
OSI(Open System Interconnection)开放系统互联模型(1)应用层: 应用层与应用程序界面沟通,以达到展示给用户的目的.(2)表示层: 表示层对网络传输的数据进行交换,使得多 ...
- 在Bean中获取spring 容器 并通过容器获取容器中其他bean
spring 提供了Awear 接口去 让bean 能感受到外界的环境.Awear 接口有很多实现,常用的有 ApplicationContextAware (可以通过实现这个接口去获取Applica ...