POJ1430 ZOJ1385 UVA1118 UVALive2431 Binary Stirling Numbers【斯特林数】
Binary Stirling Numbers
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 1971 Accepted: 794
Description
The Stirling number of the second kind S(n, m) stands for the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:
{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
The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 200. The data sets follow.
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
The output should consist of exactly d lines, one line for each data set. Line i, 1 <= i <= d, should contain 0 or 1, the value of S(ni, mi) mod 2.
Sample Input
1
4 2
Sample Output
1
Source
Regionals 2001 >> Europe - Central
Regionals 2001 >> Europe - Southwestern
问题链接:POJ1430 ZOJ1385 UVA1118 UVALive2431 Binary Stirling Numbers
问题简述:(略)
问题分析:
这是一个Stirling Numbers(斯特林数)数问题。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* POJ1430 ZOJ1385 UVA1118 UVALive2431 Binary Stirling Numbers */
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int d, n, m;
scanf("%d", &d);
for(int i = 0; i < d; i++) {
scanf("%d %d", &n, &m);
if((n - m) & (m - 1) / 2)
printf("0\n");
else
printf("1\n");
}
return 0;
}
浙公网安备 33010602011771号