← CSES Better

Count Non-Crossing Set Partitions

ZIO · 2022 · Zonal Informatics Olympiad · P2

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

combinatorics · partitions · non-crossing

The organizer’s problem statement is available at the official source link.

noncrossing partition

Partition blocks cannot cross in index order

Different blocks may not interleave as a<c in one block and b<d in another with a<b<c<d.

A---D contains B-CA--C crosses B--Dvalid: no crossing blocks
  1. 1

    Place elements in order

    Place 1…n in order and assign every element to exactly one block.
  2. 2

    Reject crossing blocks

    Check that no two blocks have alternating members.
  3. 3

    Count valid partitions

    Count distinct valid partitions with at most k blocks.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.