The Nerd Factor SPOJ - MYQ5

时间:2023-03-08 15:40:30
Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

Prof.Venky handles Advanced Topics in Algorithms course for a class of 'n' students. He is always known for his unsolvable question papers. Knowing that it is impossible to pass his subject in a fair manner, one of the students of his class, Vishy, finds out from his seniors that Prof.Venky won't be able to find out if at least 'k' students together discuss and write the answers and thereby all of them can pass. Hence they decide to divide the whole class into a number of groups so that everyone passes. But all the students are fighting over forming the groups. So Puppala, one of the nerdy students in the class, decides  that he will compute all possible ways that they can form the groups and number them, and finally choose one of those numbers at random and go ahead with that way. Now it is your duty to help Puppala find the number of  ways that they can form such groups.

Pupalla is incapable of reading big numbers, so please tell him the answer modulo 10^9+7.

Input

The first line contains the number of test case t(1<=t<=10^6). 
Followed by t lines for each case. 
Each test case contains two integers 'n' and 'k' separated by a space(1<=k,n<=1000)

Output

For each test case, print a single line containing one positive integer representing the number of ways modulo 10^9+7 .

Example

Input: 3 
2 1
4 2
6 2 Output: 2
2
4
 #include <iostream>
#include <stdio.h>
using namespace std;
#define mod 1000000007
int dp[][]={};
void init()
{
int i,j;
for(i=;i<=;i++)dp[i][i]=;
for(i=;i<=;i++)
{
for(j=i-;j>;j--)dp[i][j]=(dp[i][j+]+dp[i-j][j])%mod;
}
}
int main()
{
init();
int t,n,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
printf("%d\n",dp[n][k]);
}
return ;
}