The Nerd Factor SPOJ - MYQ5

Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

[]   [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


 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 #define mod 1000000007
 5 int dp[1100][1100]={0};
 6 void init()
 7 {
 8     int i,j;
 9     for(i=1;i<=1000;i++)dp[i][i]=1;
10     for(i=2;i<=1000;i++)
11     {
12         for(j=i-1;j>0;j--)dp[i][j]=(dp[i][j+1]+dp[i-j][j])%mod;
13     }
14 }
15 int main()
16 {
17     init();
18     int t,n,k;
19     scanf("%d",&t);
20     while(t--)
21     {
22         scanf("%d%d",&n,&k);
23         printf("%d\n",dp[n][k]);
24     }
25     return 0;
26 }
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3662797.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值