#P13485. [GCJ 2008 EMEA SemiFinal] Bus Stops

    ID: 15360 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP2008矩阵加速状压 DPGoogle Code Jam

[GCJ 2008 EMEA SemiFinal] Bus Stops

题目描述

In the First City of Mars there are NN bus stops, all aligned in a straight line of length N1N-1 km. The mayor likes to keeps things simple, so he gave the bus stops numbers from 11 to NN, and separated adjacent stops by exactly 11 km.

There are also KK buses in the city. The mayor has to plan the bus schedule and he would like to know in how many ways that can be done. This number can be very large. Luckily there are a few constraints:

  • In the beginning of the day all the buses are in the first KK bus stops (one bus per stop)
  • Buses only move from the left to the right (11 is the leftmost bus stop)
  • At the end of the day all the buses must be in the last KK bus stops (one bus per stop)
  • In each bus station exactly one bus has to stop
  • For the same bus the distance between any two consecutive stops is at most PP km

Help the mayor evaluate the number of schedules. However try not to give him very bad news (a lot of schedules) so just output the real number modulo 3003130031.

输入格式

The first line in the input file is the number of cases TT.

Each of the next TT lines contains 33 integers separated by one space: NN, KK and PP.

输出格式

For each case output the number of ways to plan the bus schedules (modulo 3003130031) in the format "Case #tt: [number of ways modulo 3003130031]" where tt is the number of the test case, starting from 11.

3
10 3 3
5 2 3
40 4 8
Case #1: 1
Case #2: 3
Case #3: 7380

提示

Sample Explanation

Let's name the buses: AA, BB, CC...

For the first case there is only one possible way of planning the schedule: A1,4,7,10A \rightarrow 1, 4, 7, 10. B2,5,8B \rightarrow 2, 5, 8. C3,6,9C \rightarrow 3, 6, 9.

For the second case the possible ways of planning are:

  • (A1,3,5.B2,4)(A \rightarrow 1,3,5. B \rightarrow 2,4),
  • (A1,3,4.B2,5)(A \rightarrow 1,3,4. B \rightarrow 2,5),
  • (A1,4.B2,3,5)(A \rightarrow 1,4. B \rightarrow 2,3,5).

Limits

  • 1<T301 < T \leq 30
  • 1<P101 < P \leq 10
  • K<NK < N
  • 1<KP1 < K \leq P

Small dataset (8 Pts, Test set 1 - Visible)

  • 1<N<10001 < N < 1000

Large dataset (26 Pts, Test set 2 - Hidden)

  • 1<N<1091 < N < 10^9