题目大意

求子集斯特林数\(\left\{\begin{matrix}n\\m\end{matrix}\right\}\%2\)

方法1 数形结合

推荐一篇超棒的博客by Sdchr

就是根据斯特林的递推式,分奇偶讨论

得到一个函数\(P_{n,m}\equiv\left\{\begin{matrix}n\\m\end{matrix}\right\}\% 2\)

再根据函数递推式通过画图,数形结合

转化成图中从一点走到另一点的方案数

变成组合问题求解

做法

这是给连插板都不会的我看的

\(a_1+a_2+...+a_n=D,a_i\ge0\)

大于等于0这个条件难易插板

我们变成

\((a_1+1)+(a_2+1)+...+(a_n+1)=D+n,(a_i+1)\ge1\)

就变成\(D+n-1\)个空隙插\(n-1\)块板了

姿势

要求阶乘中有多少个二的因子

就是\(2^1\)的倍数个数+\(2^2\)的倍数个数+\(2^3\)的倍数个数

LL num(int x){
LL res=0;
for(int i=2;i<=x;i<<=1) res+=x/i;
return res;
}

solution

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int Q=1000000007;
const int M=2003; inline LL rd(){
LL x=0;bool f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
for(;isdigit(c);c=getchar()) x=x*10+c-48;
return f?x:-x;
} int tcas;
LL n,m,D,odd; LL num(int x){
LL res=0;
for(int i=2;i<=x;i<<=1) res+=x/i;
return res;
} int Calc(int x,int y){
return num(x)-num(y)-num(x-y) == 0;
} int main(){ int i;
tcas=rd();
while(tcas--){
n=rd(),m=rd();
D=n-m;
odd=(m+1)/2;
printf("%d\n",Calc(D+odd-1,odd-1));
}
return 0;
}

方法二 斯特林数mod 2意义下与组合数关系+lucas定理

\(\left\{\begin{matrix}n\\m\end{matrix}\right\}=\dbinom {z}{w}\)

其中\(z=\lceil n-\frac {m+1} 2\rceil,w=\lfloor \frac {m-1} 2\rfloor\)

而又有结论\(\dbinom n m\%2=[n\)&\(m=m]\)

为什么,用lucas定理证一下

\(\dbinom n m\equiv \dbinom {n\%2}{m\%2}\dbinom{n/2}{m/2}(mod 2)\)

注意到这一项\(\dbinom {n\%2}{m\%2}\)

我们把n,m转为二进制

\(\binom0 1=0\),则若\(n_i=0\),\(m_i=1\),则\(\binom n m\equiv 0(mod 2)\)

\(\binom1 0=\binom 1 1=1\),则若\(n_i=1\),无论\(m_i\)为0还是1对奇偶性无影响

所以有结论

\(\dbinom n m\%2=[n\)&\(m=m]\)

poj 1430 Binary Stirling Number 求斯特林数奇偶性 数形结合| 斯特林数奇偶性与组合数的关系+lucas定理 好题的更多相关文章

  1. POJ 1430 Binary Stirling Numbers (第二类斯特林数、组合计数)

    题目链接 http://poj.org/problem?id=1430 题解 qaq写了道水题-- 在模\(2\)意义下重写一下第二类Stirling数的递推式: \[S(n,m)=S(n-1,m-1 ...

  2. poj 1430 Binary Stirling Numbers

    Binary Stirling Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1761   Accepted ...

  3. POJ 1423:Big Number 求N的阶乘的长度 斯特林公式

    Big Number Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27027   Accepted: 8626 Descr ...

  4. 求大的组合数模板 利用Lucas定理

    Lucas定理:A.B是非负整数,p是质数.A B写成p进制:A=a[n]a[n-1]…a[0],B=b[n]b[n-1]…b[0]. 则组合数C(A,B)与C(a[n],b[n])C(a[n-1], ...

  5. 学习总结:斯特林数( Stirling number )

    基本定义 第一类斯特林数:$1 \dots n$的排列中恰好有$k$个环的个数:或是,$n$元置换可分解为$k$个独立的轮换的个数.记作 $$ \begin{bmatrix} n \\ k \end{ ...

  6. POJ1430 Binary Stirling Numbers

    @(POJ)[Stirling數, 排列組合, 數形結合] Description The Stirling number of the second kind S(n, m) stands for ...

  7. 用x种方式求第n项斐波那契数,99%的人只会第一种

    大家好啊,我们又见面了.听说有人想学数据结构与算法却不知道从何下手?那你就认真看完本篇文章,或许能从中找到方法与技巧.     本期我们就从斐波那契数列的几种解法入手,感受算法的强大与奥妙吧. 原文链 ...

  8. 【Stirling Number】

    两类Stirling Number的简介与区别(参考自ACdreamer的CSDN) Stirling Number I --- s(n,k):将n个物体排成k个非空循环排列(环)的方法数. 递推式: ...

  9. 求一个数组中第K小的数

    面试南大夏令营的同学说被问到了这个问题,我的第一反应是建小顶堆,但是据他说用的是快排的方法说是O(n)的时间复杂度, 但是后来经过我的考证,这个算法在最坏的情况下是O(n^2)的,但是使用堆在一般情况 ...

随机推荐

  1. Python静态方法 类方法

    通常情况下,类中函数中定义的所有函数,,都是对象的绑定方法,除此之外,还有专门的静态方法和类方法,这两个是专门给类使用的,但是对象非要调用也是不会报错的. 对象在调用的时候会把自己传递给self,也就 ...

  2. BCB:WebBrowser 控件说明

      控件文件:system32\shdocvw.oca  shdocvw.dll 注册:regsvr32 shdocvw.dll WebBrowser 是 IE 内核做的 VB 控件, WebBrow ...

  3. bootstrap 警告(Alerts)

    本章将讲解警告(Alerts)以及bootstrap所提供的用于警告的class类.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添 ...

  4. 洛谷 2387/BZOJ 3669 魔法森林

    3669: [Noi2014]魔法森林 Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 3765  Solved: 2402[Submit][Statu ...

  5. codis 配置

    #修改dashboard.toml: coordinator_name = "zookeeper" coordinator_addr = "192.168.56.101: ...

  6. Jenkins注意点

    这里要填写 在 Linux 上 生成的 git 私钥 并且带上  前后 注释 ------start -----      ---end -------

  7. 201621123080《Java程序设计》第十一周学习总结

    201621123080<Java程序设计>第十一周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 ...

  8. nginx下配置laravel+rewrite重写

    server { listen ; server_name ha.d51v.cn; #access_log /data/wwwlogs/access_nginx.log combined; root ...

  9. Voyager的安装及配置文件

    使用代理服务器安装laravel http_proxy=http://localhost:1080 composer create-project --prefer-dist laravel/lara ...

  10. LeetCode之Weekly Contest 90

    LeetCode第90场周赛记录 第一题:亲密字符串 问题: 给定两个由小写字母构成的字符串 A 和 B ,只要我们可以通过交换 A 中的两个字母得到与 B 相等的结果,就返回 true :否则返回  ...