日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

          歡迎訪問 生活随笔!

          生活随笔

          當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

          编程问答

          POJ1430 Binary Stirling Numbers

          發布時間:2023/12/10 编程问答 30 豆豆
          生活随笔 收集整理的這篇文章主要介紹了 POJ1430 Binary Stirling Numbers 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

          @(POJ)[Stirling數, 排列組合, 數形結合]

          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

          Solution

          題意:
          求斯特林數\[ \left\{ \begin{array}{} n \\ k \end{array}{} \right\} \% 2\]\[n, m \in [1, 10^9]\]
          這題直接求解肯定是會T的, 因此考慮優化.

          轉載自sdchr博客
          侵刪



          代碼附上:

          #include<cstdio> #include<cctype> using namespace std;inline int read() {int x = 0, flag = 1;char c;while(! isdigit(c = getchar()))if(c == '-')flag *= - 1;while(isdigit(c))x = x * 10 + c - '0', c = getchar();return x * flag; }void println(int x) {if(x < 0)putchar('-'), x *= - 1;if(x == 0)putchar('0');int ans[1 << 5], top = 0;while(x)ans[top ++] = x % 10, x /= 10;for(; top; top --)putchar(ans[top - 1] + '0');putchar('\n'); }long long getQuantity(int x) {long long ret = 0;for(int i = 2; i <= x; i <<= 1)ret += x / i;return ret; }int calculate(int x, int y) {return getQuantity(x) - getQuantity(y) - getQuantity(x - y) == 0; }int main() {int T = read();while(T --){int n = read(), m = read();int d = n - m, oddQua = (m + 1) / 2;println(calculate(d + oddQua - 1, oddQua - 1));} }

          轉載于:https://www.cnblogs.com/ZeonfaiHo/p/6444001.html

          總結

          以上是生活随笔為你收集整理的POJ1430 Binary Stirling Numbers的全部內容,希望文章能夠幫你解決所遇到的問題。

          如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。