Problem:
Balls and Boxes 12

Balls

Boxes

Any way

At most one ball

At least one ball

Distinguishable

Distinguishable

1

2

3

Indistinguishable

Distinguishable

4

5

6

Distinguishable

Indistinguishable

7

8

9

Indistinguishable

Indistinguishable

10

11

12

Problem

You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.

Find the number of ways to put the balls under the following conditions:

Each ball is not distinguished from the other.

Each box is not distinguished from the other.

Each ball can go into only one box and no one remains outside of the boxes.

Each box must contain at least one ball.

Note that you must print this count modulo $10^9+7$.

Input

$n$ $k$

The first line will contain two integers $n$ and $k$.

Output

Print the number of ways modulo $10^9+7$ in a line.

Constraints

$1 \le n \le 1000$

$1 \le k \le 1000$

Sample Input 1

10 5

Sample Output 1

7

Sample Input 2

30 15

Sample Output 2

176

Sample Input 3

100 30

Sample Output 3

3910071

Solution in C# (judge verdict: Accepted)

using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
    string[] input = Console.ReadLine().Split(' ');
    long n = long.Parse(input[0]);
    long k = long.Parse(input[1]);
    long p = 1000000007;

    if(n-k < 0) Console.WriteLine(0);
    else Console.WriteLine(SplitNumber(n-k,k,p));
	}

  static long SplitNumber(long n, long k, long mod)
  {//区別しないn個の玉を区別しないk個の箱に分ける方法の個数(mod)をO(nk)で返す。
  //数え方は、dp[n,k]は、0個の箱を含む時+dp[n,k-1]、含まない時+dp[n-k,k]とする。
    long[,] dp = new long[n+1,k+1];
    
    for(int i = 0; i <= k; i++)
    {
      dp[0,i] = 1;
      for(int j = 1; j <= n; j++)
      {
        if(j-i >= 0) dp[j,i] += dp[j-i,i];
        if(i-1 >= 0) dp[j,i] += dp[j,i-1];
     
        dp[j,i] %= mod;
      }
    }

    return dp[n,k];
  }
  
}