Polygon Dissection Count
Time limit2sMemory limit128 MB
Given a convex N-gon, count the number of ways to cut it with non-crossing diagonals into exactly K polygons, modulo 1000000000, or report impossibility.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Sejun has a convex polygon with N distinct vertices. One cut must connect two vertices of the current polygon, and the cut is valid only when it divides one polygon into exactly two polygons.
Write a program that counts how many different ways there are to divide the convex N-gon into exactly K polygons.
Input
The first line contains two integers N and K.
3 <= N <= 1001 <= K <= 100
Output
Print the number of valid divisions modulo 1000000000.
If it is impossible to divide the N-gon into exactly K polygons, print -1.