传送门

题意:

求\(S(n,m)\% 2\)的值,\(n,m\leq 10^9\),其中\(S(n,m)\)是指第二类斯特林数。

思路:

因为只需要关注奇偶性,所以递推式可以写为:

  • 若\(m\)为偶数,\(S(n,m)=S(n-1,m-1)\);
  • 若\(m\)为奇数,\(S(n,m)=S(n-1,m-1)+S(n-1,m)\)。

观察第二个式子,和组合数的递推公式一模一样。所以我们可以联想到组合数。

将上述递推式子前面几项的值写出来,会发现偶数列错了前面奇数列一列,若只看奇数列,则为杨辉三角的形式。

那么将\(S(n,m)\)写成组合数的形式就为:

\[S(n,m)=C(n-\lfloor\frac{m}{2}\rfloor-1,\lceil\frac{m}{2}\rceil-1)
\]

具体怎么得出来的在纸上画一画即可。

接下来就关系\(C(n,m)\)的奇偶性,然后有个结论:

  • 若\(n\&m=m\),那么\(C(n,m)\)为奇数;否则为偶数。

然后判断一下就行。

代码如下:

/*
* Author: heyuhhh
* Created Time: 2019/12/10 21:33:03
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << '\n'; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
#define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1000 + 5; int n, m; void run(){
cin >> n >> m;
if((m & 1) == 0) {
--n, --m;
}
n = n - m / 2;
m = (m + 1) / 2;
--n, --m;
if((n & m) == m) cout << 1 << '\n';
else cout << 0 << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T;
while(T--) run();
return 0;
}

【poj1430】Binary Stirling Numbers(斯特林数+组合数)的更多相关文章

  1. POJ1430 Binary Stirling Numbers

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

  2. poj 1430 Binary Stirling Numbers

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

  3. BZOJ 2159: Crash 的文明世界(树形dp+第二类斯特林数+组合数)

    题意 给定一棵 \(n\) 个点的树和一个常数 \(k\) , 对于每个 \(i\) , 求 \[\displaystyle S(i) = \sum _{j=1} ^ {n} \mathrm{dist ...

  4. 洛谷P4609 [FJOI2016]建筑师(第一类斯特林数+组合数)

    题面 洛谷 题解 (图片来源于网络,侵删) 以最高的柱子\(n\)为分界线,我们将左边的一个柱子和它右边的省略号看作一个圆排列,右边的一个柱子和它左边的省略号看作一个圆排列,于是,除了中间的最高的柱子 ...

  5. Binary Stirling Numbers

    http://poj.org/problem?id=1430 题目: 求 第二类 斯特林数 的 奇偶性  即 求 s2 ( n , m ) % 2 : 题解: https://blog.csdn.ne ...

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

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

  7. 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) ...

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

    题目大意 求子集斯特林数\(\left\{\begin{matrix}n\\m\end{matrix}\right\}\%2\) 方法1 数形结合 推荐一篇超棒的博客by Sdchr 就是根据斯特林的 ...

  9. [2016北京集训测试赛17]crash的游戏-[组合数+斯特林数+拉格朗日插值]

    Description Solution 核心思想是把组合数当成一个奇怪的多项式,然后拉格朗日插值..:哦对了,还要用到第二类斯特林数(就是把若干个球放到若干个盒子)的一个公式: $x^{n}=\su ...

随机推荐

  1. Grafana = 可视化分析 + 监控告警

    Grafana是一个完美地分析和监控的开发平台 可以把Grafana理解为一个可视化面板(Dashboard),其实Kibana也是一个分析和可视化平台,只不过在大家的日常使用中Kibana是跟着Lo ...

  2. How to: Use XPO Upcasting in XAF 如何:在 XAF 中使用 XPO 强制转换

    In this topic, you will learn how to use the Upcasting feature of XPO in XAF. It is useful when you ...

  3. 好的js书写习惯

    1:单一判断 bad if (result) { console.log("秋叶"); } if (!result) { console.log("秋叶"); ...

  4. 前端最佳实践——DOM操作

    1.浏览器渲染原理 在讲DOM操作的最佳性能实践之前,先介绍下浏览器的基本渲染原理. 分为以下四个步骤: 解析HTML(HTML Parser) 构建DOM树(DOM Tree) 渲染树构建(Rend ...

  5. C lang:Array and Pointer formal parameter

    Test Xx_Formal parameter Formal parameter are local variable. It's private to the function. Ax_Array ...

  6. 《IM开发新手入门一篇就够:从零开发移动端IM》

        登录 立即注册 TCP/IP详解 资讯 动态 社区 技术精选 首页   即时通讯网›专项技术区›IM开发新手入门一篇就够:从零开发移动端IM   帖子 打赏 分享 发表评论162     想开 ...

  7. ReactNative: 创建自定义List列表组件

    一.介绍 在App中,很多数据消息显示都是一行行动态展示的,例如新闻标题,其实每一条新闻标题都可以独立成一个简单的列表组件,之前我们使用Text组件将数据都写死了,为了提高组件的灵活性,我们可以使用T ...

  8. Spring Boot MVC api返回的String无法关联到视图页面

    1:问题 使用 @Restcontroller 返回值定义为String 时 无法返回具体的页面 @RestController public class HelloController { @Get ...

  9. C++笔记——快读快写

    直接开始吧 额m~,这里就没什么好说的了,无非就是用getchar加快cin或printf的读入速度. 代码: inline int read() { int X=0; bool flag = 1; ...

  10. Windows10+texlive2018+texstudio

    texlive2018+texstudio下载链接 链接: https://pan.baidu.com/s/1KjPJnw1kwMBCu3qGT9rIUg 提取码: g8ha 安装texlive 解压 ...