TopcoderArchiveVisit Topcoder
SRM1 Nov 2010
SRM 502

TheCowDivTwo

Problem statement, definition, constraints, and public examples.

Problem Statement

Farmer John had N cows numbered 0 to N-1. One day he saw K cows running away from his farm. Fox Brus computed the sum of the numbers of the escaped cows. She only told John that the sum was divisible by N.

Your task is to help John by counting the number of possible sets of escaped cows. This number may be very big, so return it modulo 1,000,000,007.

Definition

Class:
TheCowDivTwo
Method:
find
Parameters:
int, int
Returns:
int
Method signature:
int find(int N, int K)
(be sure your method is public)

Constraints

  • N will be between 1 and 1,000, inclusive.
  • K will be between 1 and 47, inclusive.
  • K will be less than or equal to N.

Examples

  1. 7
    4
    Returns: 5
    7 cows are numbered 0 to 6 and 4 of them run away. Possible sets of escaped cows are {0, 1, 2, 4}, {0, 3, 5, 6}, {1, 2, 5, 6}, {1, 3, 4, 6}, {2, 3, 4, 5}.
  2. 1
    1
    Returns: 1
  3. 58
    4
    Returns: 7322
  4. 502
    7
    Returns: 704466492
  5. 1000
    47
    Returns: 219736903
Back to all problems