考虑容斥,通过$Bell(p)$的时间枚举所有等价情况。

对于一种情况,强制了一个等价类里面的数都要相同,其它的可以相同也可以不同。

这方案数显然可以通过多项式乘法求得,乘上容斥系数$(-1)^{p-等价类个数}\ \ \ \ \ \ \ \times(每个等价类大小-1)!之积$。

可以先把那$p$个多项式DFT,然后在点值表示下计算答案,最后再IDFT回来即可。

时间复杂度$O(pn(\log n+Bell(p)))$。

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long double ld;
const int N=65540;
const ld pi=acos(-1.0);
int T,C,_,P,n,m,a[N],i,j,pos[N],w[6];
struct comp{ld r,i;comp(ld _r=0,ld _i=0){r=_r,i=_i;}comp operator+(const comp&x){return comp(r+x.r,i+x.i);}comp operator-(const comp&x){return comp(r-x.r,i-x.i);}comp operator*(const comp&x){return comp(r*x.r-i*x.i,r*x.i+i*x.r);}
}f[6][N],g[N];
inline void FFT(comp*a,int n,int t){for(int i=1;i<n;i++)if(i<pos[i])swap(a[i],a[pos[i]]);for(int d=0;(1<<d)<n;d++){int m=1<<d,m2=m<<1;ld o=pi*2/m2*t;comp _w(cos(o),sin(o));for(int i=0;i<n;i+=m2){comp w(1,0);for(int j=0;j<m;j++){comp&A=a[i+j+m],&B=a[i+j],t=w*A;A=B-t;B=B+t;w=w*_w;}}}if(t==-1)for(int i=0;i<n;i++)a[i].r/=n;
}
void dfs(int x,int y){if(x==P){int i,j,k=(P-y)&1?-1:1;for(i=1;i<=y;i++)for(j=2;j<w[i];j++)k*=j;comp t(k,0);for(j=0;j<m;j++)g[j]=f[w[1]][j];for(i=2;i<=y;i++)for(j=0;j<m;j++)g[j]=g[j]*f[w[i]][j];for(j=0;j<m;j++)f[0][j]=f[0][j]+g[j]*t;return;}for(int i=1;i<=y+1;i++){w[i]++;dfs(x+1,max(i,y));w[i]--;}
}
int main(){scanf("%d",&T);while(T--){scanf("%d%d",&_,&P);for(n=i=0;i<_;i++){scanf("%d",&a[i]);if(a[i]>n)n=a[i];}n*=P;for(m=1;m<=n;m<<=1);j=__builtin_ctz(m)-1;for(i=0;i<m;i++)pos[i]=pos[i>>1]>>1|((i&1)<<j);for(i=0;i<=P;i++)for(j=0;j<m;j++)f[i][j]=comp(0,0);for(i=0;i<_;i++)for(j=1;j<=P;j++)f[j][j*a[i]].r+=1;for(i=1;i<=P;i++)FFT(f[i],m,1);dfs(0,0);FFT(f[0],m,-1);for(j=i=1;i<=P;i++)j*=i;printf("Case #%d:\n",++C);for(i=1;i<m;i++){ld ans=f[0][i].r/j;if(ans>0.5)printf("%d: %.0f\n",i,(double)ans);}puts("");}return 0;
}

  

BZOJ2498 : Xavier is Learning to Count相关推荐

  1. 物体计数--Learning To Count Objects in Images

    Learning To Count Objects in Images NIPS 2010 http://www.robots.ox.ac.uk/~vgg/research/counting/ Mat ...

  2. 人群密度估计--Learning to Count with CNN Boosting

    Learning to Count with CNN Boosting ECCV2016 本文使用CNN来进行人群密度估计,主要有两个改进地方:layered boosting and selecti ...

  3. [论文笔记 ECCV2020] Learning to Count in the Crowd from Limited Labeled Data

    [论文笔记 ECCV2020] Learning to Count in the Crowd from Limited Labeled Data 摘要 Abstract 贡献 Contribution ...

  4. 【论文笔记】Learning to Count in the Crowd from Limited Labeled Data

    文章目录 Abstract 1 Introduction 3 Preliminaries 4 GP-based iterative learning 4.1 Labeled stage 4.2 Unl ...

  5. GitHub 3.6k Satr自监督学习(Self-Supervised Learning)资源你值得拥有!

    自我监督学习已成为AI社区中令人兴奋的方向. Jitendra Malik: "Supervision is the opium of the AI researcher" Aly ...

  6. 人车密度估计--Towards perspective-free object counting with deep learning

    Towards perspective-free object counting with deep learning ECCV2016 https://github.com/gramuah/ccnn ...

  7. 人群计数最全代码、数据、论文合集

    2021.11.19更新: 人群计数 /Crowd Counting Rethinking Counting and Localization in Crowds:A Purely Point-Bas ...

  8. CVPR 2021 论文和开源项目合集(Papers with Code)

    摘自:https://github.com/amusi/CVPR2021-Papers-with-Code CVPR 2021 论文和开源项目合集 CVPR 2021 论文和开源项目合集(Papers ...

  9. 朴素贝叶斯实现分类_关于朴素贝叶斯分类及其实现的简短教程

    朴素贝叶斯实现分类 Naive Bayes classification is one of the most simple and popular algorithms in data mining ...

最新文章

  1. PE里在计算机本地磁盘大小,没有U盘如何在电脑本地磁盘制作一个PE系统
  2. redmine 2.2.x 修改文档附件的存放目录
  3. [luogu2576 SCOI2010] 幸运数字 (容斥原理)
  4. stm32f4xx 的EXTI使用的一般步骤
  5. SAP UI5 view.setModel will trigger binding creation
  6. 怎样用php写入数据库表,PHP如何将数据写入到MYSQL数据库
  7. MySQL 之 information_schema
  8. mask_rcnn训练自己的数据集
  9. [转]其实每个男孩都想做一个感情专一的好男人
  10. [论文阅读] Pyramid Feature Attention Network for Saliency Detection
  11. iis6xp_xp安装iis6步骤方法
  12. 如何在matlab中打开图片
  13. 苹果M1如何安装Rosetta
  14. spacy实体关系抽取_使用spacy从Wikipedia文章中命名实体识别
  15. 大数据应用技术实验报告六 Hive和MySQL
  16. 桌面快捷图标变成白色处理方案
  17. 复数运算(友元函数)
  18. wince 百度地图懒人包_【分享】路虎高德V6.0+V33图资懒人包(WIN CE)【亲测】
  19. 第7周项目5 排队看病模拟
  20. 我眼中的CTO:提升IT管理的价值

热门文章

  1. python基础课程第12章,Python基础教程学习笔记 | 第12章 | 图形用户界面
  2. 刘夏真的简历中国科学院计算机所,专家人才库数据----中国科学院计算技术研究所...
  3. 计算机网络 物理层链路层
  4. Dijkstra的算法
  5. 【 MATLAB 】fliplr 函数介绍(从左到右翻转阵列)
  6. 【SharePoint】设置站点通讯组
  7. digitalocean如何还原出厂设置
  8. Java类中的权限修饰符
  9. python中itertools模块介绍---03
  10. C语言的 32个关键之和9个控制语言之关键字