The Nerd Factor SPOJ - MYQ5
Time Limit: 1000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
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 ;
}
The Nerd Factor SPOJ - MYQ5的更多相关文章
- 【SPOJ】1812. Longest Common Substring II(后缀自动机)
http://www.spoj.com/problems/LCS2/ 发现了我原来对sam的理解的一个坑233 本题容易看出就是将所有匹配长度记录在状态上然后取min后再对所有状态取max. 但是不要 ...
- SPOJ Lexicographical Substring Search 后缀自动机
给你一个字符串,然后询问它第k小的factor,坑的地方在于spoj实在是太慢了,要加各种常数优化,字符集如果不压缩一下必t.. #pragma warning(disable:4996) #incl ...
- 【刷题】SPOJ 1811 LCS - Longest Common Substring
A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...
- SPOJ 1812 Longest Common Substring II(后缀自动机)(LCS2)
A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- SPOJ LCS2 - Longest Common Substring II
LCS2 - Longest Common Substring II A string is finite sequence of characters over a non-empty finite ...
- Leetcode 254. Factor Combinations
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
随机推荐
- express传输buffer文件
最近要做一个功能,导出动态生成的excel文件,这个普普通通的功能却让我折腾了半天.大致流程是这样的,将数据结合excel模板通过ejsExcel库,动态生成excel文件,并发送到客户端. 在exp ...
- 防止fixed元素遮挡其他元素的方法
有多个页面,有的有固定的头部(设置了postion:fixed的元素),有的没有固定的头部,这时就有个问题,有固定头部的页面,头部会遮挡下面的内容,那怎么解决呢? <!DOCTYPE html& ...
- MongoDB学习之路(二)
MongDB特点 MongoDB是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器的性能. MongoDB旨在为WEB应用提供可拓展的高 ...
- 轻谈 return i++
在写函数的时候,发现了又一个很有意思的事情 先上代码 public class Test{ static int number = 2; public static void main(String ...
- 团队作业8——第二次项目冲刺(Beta版本)5.24
1.当天站立式会议照片 会议内容 1.总结前几次会议中出现的问题. 2.对第二天需要做的任务进行分配. 3.询问团队队员任务完成情况以及时间分配是否充分. 4.对今后的任务,发表自己的看法. 2.每个 ...
- 201521123107 《Java程序设计》第10周学习总结
第10周作业-异常与多线程 1.本周学习总结 2.书面作业 1.finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? 只有try块中 ...
- 201521123086 《Java程序设计》第8周学习总结
本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 书面作业 1.List中指定元素的删除 题集jmu-Java-05-集合之4-1 1.1 实验总结 Answer: ...
- 201521123022 《Java程序设计》 第8周学习总结
1.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 Q1.List中指定元素的删除(题目4-1) Q1.1 实验总结 本题要求的是编写covnert ...
- 201521123064 《Java程序设计》第7周学习总结
1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 Q1:ArrayList代码分析 1.1 解释ArrayList的contains源 ...
- 201521044091《java程序设计》第四次总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.11.2 使用常规方法总结其他上课内容 Object是所有对象类的父类,而toString方法只有可以转换为字符串的类型对象才可 ...