Problems > Ways to Partition a Set

Ways to Partition a Set

Difficulty: 1800 5000 ms 128 MB

dp combinatorics

Count the ways to partition a set of N labelled elements into any number of non-empty unlabelled groups — the Bell number B(N) — modulo 109+7.

Input: one integer N.

Output: B(N) mod 109+7.

Constraints:

  • 0 ≤ N ≤ 3000

Sample Tests

Input 1
3
Output 1
5
Input 2
0
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.