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 ...
随机推荐
- [2012-08-06]awk多文件合并并按文件名分段
以下代码满足这样的需求: 多个文件内容合并到一个文件A中(如果没有下面这条,使用cat就能解决) 文件A中每段内容之前保留原先的文件名 awk 'tmp!=FILENAME{tmp=FILENAME; ...
- JRE 和 JDK 的区别
JRE顾名思义是java运行时环境,包含了java虚拟机,java基础类库.是使用java语言编写的程序运行所需要的软件环境,是提供给想运行java程序的用户使用的. JDK顾名思义是java开发 ...
- DateTable转化为泛型集合
public class ListUtil { public static List<T> ToList<T>(DataTable dt) { List<T> li ...
- 使用 Palette 让你的 UI 色彩与内容更贴合
版权声明: 本账号发布文章均来自公众号,承香墨影(cxmyDev),版权归承香墨影所有. 每周会统一更新到这里,如果喜欢,可关注公众号获取最新文章. 未经允许,不得转载. 一.前言 今天介绍一个 An ...
- C#设计模式(5)-建造者模式
引言 上一篇介绍了设计模式中的抽象工厂模式-C#设计模式(3)-抽象工厂模式,本篇将介绍建造者模式: 点击这里查看全部设计模式系列文章导航 建造者模式简介 建造者模式是将一个复杂对象的构建与表示分离, ...
- el-input监听不了回车事件
vue使用element-ui的el-input监听不了回车事件,原因应该是element-ui自身封装了一层input标签之后,把原来的事件隐藏了,所以如下代码运行是无响应的: <el-inp ...
- Kafka Streams 剖析
1.概述 Kafka Streams 是一个用来处理流式数据的库,属于Java类库,它并不是一个流处理框架,和Storm,Spark Streaming这类流处理框架是明显不一样的.那这样一个库是做什 ...
- Core Java 谈谈HashMap
说起Java的HashMap相信大家都不是很陌生,但是对于HashMap内部结构有些同学可能不太了解,咱们下一步就将其展开. HashMap是基于Hash算法的,同理的还有HashSet和HashTa ...
- datable 翻页事件处理
JQuery datatable插件,点下一页在点击事件无效问题 (2013-10-16 16:01:54) 转载▼ 分类: C# 在MVC的项目中,我利用jquery datatable 来实现 ...
- JFrame常用属性设置模板
最近在学习Swing,在各种demo中都需要构建JFrame,于是我决定把构建JFrame的代码贴上来,以后就直接复制粘贴了. public static void main(String[] arg ...