← Complete problem index

PROJECT EULER · #0907

Stacking Cups

Statement only · UnsolvedOriginal problem ↗

An infant's toy consists of n cups, labelled C1,,Cn in increasing order of size.

0907_four_cups.png

The cups may be stacked in various combinations and orientations to form towers. The cups are shaped such that the following means of stacking are possible:

  • Nesting: Ck may sit snugly inside Ck+1.
    0907_nesting.png
  • Base-to-base: Ck+2 or Ck2 may sit, right-way-up, on top of an up-side-down Ck, with their bottoms fitting together snugly.
    0907_base_to_base.png
  • Rim-to-rim: Ck+2 or Ck2 may sit, up-side-down, on top of a right-way-up Ck, with their tops fitting together snugly.
    0907_rim_to_rim.png
  • For the purposes of this problem, it is not permitted to stack both Ck+2 and Ck2 rim-to-rim on top of Ck, despite the schematic diagrams appearing to allow it:
    0907_rim_to_rim_counter_example.png

Define S(n) to be the number of ways to build a single tower using all n cups according to the above rules.
You are given S(4)=12, S(8)=58, and S(20)=5560.

Find S(107), giving your answer modulo 1000000007.

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.