Division of "Recursive and recursive" sets

Source: Internet
Author: User

Division of "Recursive and recursive" sets The topic description is set S is a set of n elements, S={a1,a2,......, an}, now divides s into K to meet the following conditions of a subset of S1,s2,......, SK, and satisfies:
(1) si≠∅
(2) Si∩sj=∅
(3) S1∪s2∪s3∪ ... ∪sk=s
It is called S1,s2,..., SK is a division of the set S. It is equivalent to the N elements in the s set A1,a2,..., an into K (0<k≤n<30) unlabeled box, so that no box is empty. Please make sure that n elements a1,a2,..., the number of divisions s (n,k) that go into the K-unlabeled box. Enter two integers n and k to output an integer, dividing the number of S (n,k). Sample input
4 3
Analysis: The second type of Stirling number; (one of the ball box models)
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e4+Ten;Const intdis[][2]={0,1,-1,0,0,-1,1,0};using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p%mod;p=p*p%mod;q>>=1;}returnF;}intDfsintXinty) {    if(x<y| | y==0)return 0; Else if(y==1|| X==y)return 1; Else returnDFS (X-1, Y1) +y*dfs (x1, y);}intMain () {inti,j,m,n,k,t; scanf ("%d%d",&n,&m); cout<<dfs (n,m) <<Endl; //System ("pause");    return 0;}

Division of "Recursive and recursive" sets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.