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的<组合数学>,那本书的这一章写的很详细也很容易理解.最好能 ...
随机推荐
- python-2函数
http://docs.python.org/3/library/functions.html 或者菜鸟中文资料 1-使用函数 abs(-20)#求绝对值 max(1,4,200,3,2) #求最大的 ...
- Apache 设置二级域名
开启重写模块 LoadModule rewrite_module modules/mod_rewrite.so 编辑配置 NameVirtualHost *:80 <VirtualHost *: ...
- python语言中threading.Thread类的使用方法
1. 编程语言里面的任务和线程是很重要的一个功能.在python里面,线程的创建有两种方式,其一使用Thread类创建 # 导入Python标准库中的Thread模块 from threading i ...
- 《Cracking the Coding Interview》——第12章:测试——题目1
2014-04-24 23:10 题目:找出下面代码里的错误. 解法:请看下面. 代码: // 12.1 What's wrong with the following code segment? # ...
- php静态文件返回304
有时一些静态文件(如图片)会由php输出,会发现请求都是200,静态文件每次都去服务器上请求太浪费资源了,这时如何让浏览器缓存图片呢?就需要我们在php中输出304了. 我们可以利用php中的 HTT ...
- 去掉referer信息
<iframe src="auto-refresh.html" width=500 height=500 rel="noreferrer">< ...
- JMeter学习笔记(五) 文件上传接口测试
此次测试的是上传图片接口,我把测试情况整理了一下,其他的上传文件接口都类似. 1.我通过jmeter的录制功能获取到了接口地址以及相关参数,如果有接口文档就会方便很多,此步骤就不多做说明了 2.因为上 ...
- linux部署环境配置
https://blog.csdn.net/dsczxcc/article/details/78728330
- Vue2 全局过滤器(vue-cli)
先看官方简介: 当前组件注册: export default { data () { return {} }, filters:{ orderBy (){ // doSomething }, uppe ...
- NodeJs06 高并发
高并发架构 在业务的最初期,由于业务和用户的体量比较小,可能采用单机就足够了.随着业务的增长,用户量和并发请求量都会不断上升.当增长到一定的瓶颈的时候,系统能否抗住压力,就需要采取一些方案了.这就是著 ...