UVALIVE 2431 Binary Stirling Numbers
转自别人的博客。这里记录一下
这题是定义如下的一个数:
S(0, 0) = 1; S(n, 0) = 0 for n > 0;S(0, m) = 0 for m > 0;
S(n, m) = m S(n - 1, m) + S(n - 1, m - 1), for n, m > 0.
也就是题中所说的把一个含有n个元素的集合分成m份,共有多少种分法。
现在题目就是要求S(n, m)的奇偶性。
如果m是一个偶数的话,那么我们可以推出 S(n, m) Ξ S(n-1, m-1) (mod 2),如果m是一个奇数的话,我们推出S(n, m) Ξ (S(n-1, m) + S(n-1, m-1)) (mod 2)。后面看到某一大牛所说的利用画图来推导这个表达式,整了一下,S(n, m)这个状态可由左边的S(n-1, m) 以及 斜下方的 S(n-2, m-2)得到。最后得到结果是c( n-m, n-m+(m-1)/2 ).
最后只要确定一个组合数是否为奇数即可,c(A, B) = B! / (A! * (B-A)!) 我们通过提取上下阶乘的2的个数即可,因为这个式子一定能够约分成整数,那么只要2这个因子没有就一定是一个奇数了。
代码:
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; int main()
{
int T, n, m, t1, t2;
scanf("%d", &T);
while (T--) {
t1 = t2 = ;
scanf("%d %d", &n, &m);
if (m == && n) {
puts("");
continue;
}
n -= m;
m = n + (m-)/; // n此处就是n-m了
int A = n, B = m, C = (B-A);
while (B) {
t1 += B/;
B /= ;
}
while (A) {
t2 += A/;
A /= ;
}
while (C) {
t2 += C/;
C /= ;
}
if (t1 == t2) {
puts("");
}
else {
puts("");
}
}
return ;
}
UVALIVE 2431 Binary Stirling Numbers的更多相关文章
- poj 1430 Binary Stirling Numbers
Binary Stirling Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1761 Accepted ...
- POJ1430 Binary Stirling Numbers
@(POJ)[Stirling數, 排列組合, 數形結合] Description The Stirling number of the second kind S(n, m) stands for ...
- POJ 1430 Binary Stirling Numbers (第二类斯特林数、组合计数)
题目链接 http://poj.org/problem?id=1430 题解 qaq写了道水题-- 在模\(2\)意义下重写一下第二类Stirling数的递推式: \[S(n,m)=S(n-1,m-1 ...
- 【poj1430】Binary Stirling Numbers(斯特林数+组合数)
传送门 题意: 求\(S(n,m)\% 2\)的值,\(n,m\leq 10^9\),其中\(S(n,m)\)是指第二类斯特林数. 思路: 因为只需要关注奇偶性,所以递推式可以写为: 若\(m\)为偶 ...
- Binary Stirling Numbers
http://poj.org/problem?id=1430 题目: 求 第二类 斯特林数 的 奇偶性 即 求 s2 ( n , m ) % 2 : 题解: https://blog.csdn.ne ...
- UVALive - 6577 Binary Tree 递推+找规律
题目链接: http://acm.hust.edu.cn/vjudge/problem/48421 Binary Tree Time Limit: 3000MS 问题描述 Binary Tree is ...
- UVALive 6577 Binary Tree 二叉树的LRU串
今天继续攒人品...真开心啊O(∩_∩)O~~各种身体不舒服~~ https://icpcarchive.ecs.baylor.edu/external/65/6577.pdf 题意是这样的,现在有一 ...
- poj 1430 Binary Stirling Number 求斯特林数奇偶性 数形结合| 斯特林数奇偶性与组合数的关系+lucas定理 好题
题目大意 求子集斯特林数\(\left\{\begin{matrix}n\\m\end{matrix}\right\}\%2\) 方法1 数形结合 推荐一篇超棒的博客by Sdchr 就是根据斯特林的 ...
- acm数学(转)
这个东西先放在这吧.做过的以后会用#号标示出来 1.burnside定理,polya计数法 这个大家可以看brudildi的<组合数学>,那本书的这一章写的很详细也很容易理解.最好能 ...
随机推荐
- java8之list集合中取出某一属性的方法
上代码 List<User> list = new ArrayList<User>(); User user1 = new User("第一位"," ...
- Description POJ1703
Description The police office in Tadu City decides to say ends to the chaos, as launch actions to ro ...
- PHP.19-验证码生成
生成验证码 思路:先定义验证码函数getCode() //绘制验证码 $num = 4; //字符长度 getCode($num, 2); 1.创建画布,分配颜色 imagecreatetruecol ...
- Android 如何在xmL 里面动态设置padding
如题,Android 如何在xmL 里面动态设置padding 有时候,你的布局加载完成之后,你findViewByid 找到控件,设置padding 会导致白条,布局闪动,那怎么办呢? 你是不是就想 ...
- 开启虚拟机所报的错误:VMware Workstation cannot connect to the virtual machine. Make sure you have rights to run the program, access all directories the program uses, and access all directories for temporary fil
当我们开启虚拟机时出现错误: VMware Workstation cannot connect to the virtual machine. Make sure you have rights t ...
- [转]赵桐正thinkphp教程笔记
原文:赵桐正thinkphp教程笔记 ,有修改 常用配置 常用配置config.php: <?php return array( //'配置项'=>'配置值' 'URL_PATHINFO_ ...
- 【Dual Support Vector Machine】林轩田机器学习技法
这节课内容介绍了SVM的核心. 首先,既然SVM都可以转化为二次规划问题了,为啥还有有Dual啥的呢?原因如下: 如果x进行non-linear transform后,二次规划算法需要面对的是d`+1 ...
- script通过script标签跨域加载数据
/********************************************************** 说明:跨域请求数据Javascript组件 ------------------ ...
- Centos在VMware虚拟机上的网络配置一记
症状:配置好了IP, ping 127.0.0.1 ok ping 10.0.0.1 ok ping 外网IP,域名 network is unreachable ------- ...
- 【转载】Linux下安装LoadRunner LoadGenerator
原文地址:[转载]Linux下安装LoadRunner LoadGenerator作者:邱建忠tester LR的负载机安装在linux的理由: 1.windows xp,双核+4G内存,基本上每个v ...