QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 34

#5782. King

統計

Problem

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

There are also K 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 K bus stops (one bus per stop)
  • Buses only move from the left to the right (1 is the leftmost bus stop)
  • At the end of the day all the buses must be in the last K 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 P 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 30031.

Input

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

Each of the next T lines contains 3 integers separated by one space: N, K and P.

Output

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

Limits

Time limit: 30 5 seconds per test set.

Memory limit: 1GB.

1 < T ≤ 30

1 < P ≤ 10

K < N

1 < KP

Small dataset (Test set 1 - Visible; 8 Points)

1 < N < 1000

Large dataset (Test set 2 - Hidden; 26 Points)

1 < N < 109

Sample

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

Let's name the buses: A, B, C...

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

For the second case the possible ways of planning are:

(A → 1,3,5. B → 2,4),

(A → 1,3,4. B → 2,5),

(A → 1,4. B → 2,3,5).

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.