Summary of the first class of the second class of Stirling

Source: Internet
Author: User
Tags cas printf cmath


The first class of Stirling number is positive or negative, and its absolute value is the number of methods that contain n elements that are arranged as K-rings.
The recursive formula is, S (n,0) = 0, S (= 1). S (n+1,k) = S (n,k-1) + NS (n,k).
Boundary conditions: s (0, 0) = 1 s (p, 0) = 0 p>=1 s (p, p) =1 p>=0
Some properties: S (P, 1) = 1 p>=1 s (P, 2) = 2^ (p-1) –1 p>=2


The second class of Stirling is the number of methods that divide the set of n elements into exactly k non-empty-empty sets.
The recursive formula is: S (n,k) = 0; (n<k| | k=0) s (n,n) = S (n,1) = 1,
S (n,k) = S (n-1,k-1) + KS (n-1,k).
Consider the P item, p can be a separate non-empty set, when the first p-1 items constitute k-1 non-empty
An irreducible set, the number of methods is S (p-1,k-1);
It is also possible for the former p-1 to form K non-empty indistinguishable sets,
P items are put into any one, so there are k*s (P-1,k) methods.



Sdut 2883

N games, M cards (n>=m) with one card per game,

Each card is used at least once, asking for several options.

Analysis: N games are divided into M-sets, each of which matches only the same card,

There are no empty collections. That is, the number of methods that divide a set of n elements into exactly m non-empty

Then multiply m in full alignment.


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <queue>
#include <stack>
#include <list>

using namespace std;
typedef long long LL;
const LL MOD=1E9+7;

ll sum[110][110];
ll jiec[102];

int main () {
	jiec[0]=1;jiec[1]=1;jiec[2]=2;
    for (ll i=3;i<102;i++) {
        jiec[i]= (jiec[i-1]*i)%mod;
    }
	for (ll i=0;i<=102;i++) {for
		(ll j=0;j<=102;j++) {
			if (j==0 | | j>i) sum[i][j]=0;
			else if (i==j | | j==1) sum[i][j]=1;
			else sum[i][j]= (Sum[i-1][j-1] + j*sum[i-1][j])%mod;
		}
	}
	int n,m;
	while (scanf ("%d%d", &n,&m)!=eof) {
		printf ("%lld\n", (Jiec[m]*sum[n][m])%mod);
	}



	return 0;
}




Sdut 3144

Now give you a number of s of size n, output the total number of methods that divide it into sets ans is how much.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <queue>
#include <stack>
#include <list>

using namespace std;
typedef long long LL;
const LL MOD=1E9+7;
const int maxn=5002;

ll SUM[2][MAXN];
ll ANS[MAXN];


void  cal () {for
    (ll i=0;i<maxn;i++) {
		ans[i]=0;
		for (ll j=0;j<maxn;j++) {
			if (j==0 | | j>i) sum[i%2][j]=0;
			else if (i==j | | j==1) sum[i%2][j]=1;
			Else sum[i%2][j]= (sum[(i-1)%2][j-1] + j*sum[(i-1)%2][j])%mod;
			Ans[i]= (Ans[i]+sum[i%2][j])%mod;



}} int main () {
	cal ();
	int n;
	int Cas=1;
	while (scanf ("%d", &n)!=eof) {
		printf ("Case #%d:%lld\n", cas++,ans[n]%mod);
	}
	return 0;
}







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.