poj 1430 Binary Stirling Numbers
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 1761 | Accepted: 671 |
Description
{1, 2, 3} U {4}, {1, 2, 4} U {3}, {1, 3, 4} U {2}, {2, 3, 4} U {1}
{1, 2} U {3, 4}, {1, 3} U {2, 4}, {1, 4} U {2, 3}.
There is a recurrence which allows to compute S(n, m) for all m and n.
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.
Your task is much "easier". Given integers n and m satisfying 1 <= m <= n, compute the parity of S(n, m), i.e. S(n, m) mod 2.
Example
S(4, 2) mod 2 = 1.
Task
Write a program which for each data set:
reads two positive integers n and m,
computes S(n, m) mod 2,
writes the result.
Input
Line i + 1 contains the i-th data set - exactly two integers ni and mi separated by a single space, 1 <= mi <= ni <= 10^9.
Output
Sample Input
1
4 2
Sample Output
1
Source
可以转化成求C(N,M)来做。当然不是直接转化。
打出表看一下,发现是有规律的。
每一列都会重复一次。打表看一下吧。
思路:
s(n,m) 如果m是偶数 n=n-1; m=m-1;==>转化到它的上一个s(n-1,m-1);
k=(m+1)/2; n=n-k; m=m-k;求C(n,m)的奇偶性就可以了。(当然有很多书写方式,不一定要这样做。)
测试用的
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int dp[][];
int cnm[][];
void init()
{
int i,j;
dp[][]=;
for(i=;i<=;i++) dp[i][]=;
for(i=;i<=;i++)
for(j=;j<=i;j++)
dp[i][j]=dp[i-][j-]+dp[i-][j]*j;
for(i=;i<=;i++)
{
for(j=;j<=i;j++)
printf("%d ",(dp[i][j]&));
printf("\n");
} cnm[][]=;
for(i=;i<=;i++)
{
cnm[i][]=;
cnm[][i]=;
}
for(i=;i<=;i++)
{
for(j=;j<=i;j++)
{
if(j==) cnm[i][j]=i;
else if(i==j) cnm[i][j]=;
else cnm[i][j]=cnm[i-][j]+cnm[i-][j-];
}
}
for(i=;i<=;i++)
{
for(j=;j<=i;j++)
printf("%d ",cnm[i][j]&);
printf("\n");
}
}
int main()
{
init();
int n,m;
while(scanf("%d%d",&n,&m)>)
{
printf("%d\n",dp[n][m]);
}
return ;
}
ac代码
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int a[],alen;
int b[],blen;
void solve(int n,int m)
{
int i;
bool flag=false;
alen=;
blen=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
while(n)
{
a[++alen]=(n&);
n=n>>;
}
while(m)
{
b[++blen]=(m&);
m=m>>;
}
for(i=; i<=alen; i++)
{
if(a[i]== && b[i]==) flag=true;
if(flag==true) break;
}
if(flag==true)printf("0\n");
else printf("1\n");
}
int main()
{
int T;
int n,m,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
if(m%==)
{
n=n-;
m=m-;
}
k=(m+)/;
solve(n-k,m-k);
}
return ;
}
poj 1430 Binary Stirling Numbers的更多相关文章
- POJ 1430 Binary Stirling Numbers (第二类斯特林数、组合计数)
题目链接 http://poj.org/problem?id=1430 题解 qaq写了道水题-- 在模\(2\)意义下重写一下第二类Stirling数的递推式: \[S(n,m)=S(n-1,m-1 ...
- poj 1430 Binary Stirling Number 求斯特林数奇偶性 数形结合| 斯特林数奇偶性与组合数的关系+lucas定理 好题
题目大意 求子集斯特林数\(\left\{\begin{matrix}n\\m\end{matrix}\right\}\%2\) 方法1 数形结合 推荐一篇超棒的博客by Sdchr 就是根据斯特林的 ...
- POJ1430 Binary Stirling Numbers
@(POJ)[Stirling數, 排列組合, 數形結合] Description The Stirling number of the second kind S(n, m) stands for ...
- Binary Stirling Numbers
http://poj.org/problem?id=1430 题目: 求 第二类 斯特林数 的 奇偶性 即 求 s2 ( n , m ) % 2 : 题解: https://blog.csdn.ne ...
- 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) ...
- 【poj1430】Binary Stirling Numbers(斯特林数+组合数)
传送门 题意: 求\(S(n,m)\% 2\)的值,\(n,m\leq 10^9\),其中\(S(n,m)\)是指第二类斯特林数. 思路: 因为只需要关注奇偶性,所以递推式可以写为: 若\(m\)为偶 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- 笛卡尔树 POJ ——1785 Binary Search Heap Construction
相应POJ 题目:点击打开链接 Binary Search Heap Construction Time Limit: 2000MS Memory Limit: 30000K Total Subm ...
- POJ - 3252 A - Round Numbers
The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' ...
随机推荐
- JAVA的JVM虚拟机工作原理.V.1.0.0
注意:一下内容纯属个人理解,如有错误,欢迎批评指正. (90度弯腰)谢谢. java在JVM上的运行过程: 1,编辑好的java代码(IDE无报错,测试运行无错误): 2,java源代码通过javac ...
- 转:MIME(Multipurpose Internet Mail Extensions)类型
MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- having 子句
having 子句-->过滤分组,用于限制分组显示结果 a.行已经被分组 b.使用了分组函数 c.满足having子句中条件的分组将被重写
- HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)
Problem Description There is an old country and the king fell in love with a devil. The devil always ...
- paper 10:支持向量机系列七:Kernel II —— 核方法的一些理论补充,关于 Reproducing Kernel Hilbert Space 和 Representer Theorem 的简介。
在之前我们介绍了如何用 Kernel 方法来将线性 SVM 进行推广以使其能够处理非线性的情况,那里用到的方法就是通过一个非线性映射 ϕ(⋅) 将原始数据进行映射,使得原来的非线性问题在映射之后的空间 ...
- webpack.config.js
var webpack = require('webpack'); module.exports = { //插件项 plugins: [ new webpack.optimize.CommonsCh ...
- ubuntu sublime-text package control
1.ubuntu 环境下sublime-text的 package control一直配置失败 因为我下的是sublime-text3,而网上一般都是sublime-text2的教程. 2.subli ...
- java连接数据库URL
转: 1.Oracle数据库 Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String url ...
- android 项目学习随笔十九(MD5)
import java.security.MessageDigest; public class MD5Encoder { public static String encode(String str ...
- python核心编程学习记录之基础知识
虽然对python的基础知识有所了解,但是为了更深入的学习,要对python的各种经典书籍进行学习 第一章介绍python的优缺点,略过 第二章介绍python起步,第三章介绍python基础,仅记录 ...