D. Beautiful Pairs of Numbers
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled:

  • 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer;
  • all numbers b1 - a1, b2 - a2, ..., bk - ak are distinct.

For the given number n find the number of beautiful sequences of length k. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer t (1 ≤ t ≤  2·105) — the number of the test data.

Each of the next t lines contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

Output

For each test from the input print the answer to the problem modulo 1000000007 (109 + 7). Print the answers to the tests in the order in which the tests are given in the input.

Sample test(s)
input
6
1 1
2 1
2 2
3 1
3 2
3 3
output
1
3
0
6
2
0
Note

In the first test sample there is exactly one beautiful sequence: (1, 1).

In the second test sample, the following sequences are beautiful:

  • (1, 1);
  • (1, 2);
  • (2, 2).

In the fourth test sample, the following sequences are beautiful:

  • (1, 1);
  • (1, 2);
  • (1, 3);
  • (2, 2);
  • (2, 3);
  • (3, 3).

In the fifth test sample, the following sequences are beautiful:

  • (1, 1), (2, 3);
  • (1, 2), (3, 3).

In the third and sixth samples, there are no beautiful sequences.

dp 背包问题

预处理fac[i] 为 i!   c[i][j] 为组合数 dp[i][j] 代表 i 体积中装 j 个物品

dp[i][j] = dp[i - j][j - 1] + dp[i - j][j];

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long ll; const int MOD = 1e9 + ,N = ;
ll c[N + ][N + ],dp[N + ][N + ],fac[N + ]; void init() {
fac[] = ;
for(int i = ; i <= N; ++i) {
fac[i] = fac[i - ] * i % MOD;
} for(int i = ; i <= N; ++i) {
c[i][] = c[i][i] = ;
for(int j = ; j < i; ++j) {
c[i][j] = (c[i - ][j] + c[i - ][j - ]) % MOD;
}
} dp[][] = ;
for(int i = ; i <= N; ++i) {
for(int j = ; j <= i; ++j) {
dp[i][j] = (dp[i - j][j] + dp[i - j][j - ]) % MOD;
}
}
}
int main()
{
init();
int t;
scanf("%d",&t); while(t--) {
int n,k,ans = ;
scanf("%d%d",&n,&k);
for(int s = k * (k + ) / ; s <= n; ++s) {
ans = (ans + dp[s][k] * c[n - s + k][k]) % MOD;
} printf("%d\n",ans * fac[k] % MOD); }
//cout << "Hello world!" << endl;
return ;
}

cf 403 D的更多相关文章

  1. 【题解】CF#403 D-Beautiful Pairs of Numbers

    这题还挺对胃口的哈哈~是喜欢的画风!回家路上一边听歌一边想到的解法,写出来记录一下…… 首先,由于 \(b_{k} < a_{k + 1}\) ,所以我们可以看作是在一个长度为 n 的序列上选择 ...

  2. Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)

    The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...

  3. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  4. apache httpd服务器403 forbidden的问题

    一.问题描述 在apache2的httpd配置中,很多情况都会出现403. 刚安装好httpd服务,当然是不会有403的问题了.主要是修改了一些配置后出现,问题描述如下: 修改了DocumentRoo ...

  5. 遇到 HTTP 错误 403.14 - Forbidden?

    打开 http://localhost:1609 报错: HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容 解决方案一:设置默认首页 在 Web.conf ...

  6. nginx 访问目录403

    centos7.2默认安装好nginx后,会在/usr/share/nginx/html下作为主目录 但是如果想访问下面的目录会发现没有权限,返回403错误 这时候要注意在/etc/nginx/ngi ...

  7. Apache2.4部署django出现403 Forbidden错误解决办法

    前言:Apache2.4部署django出现403 Forbidden错误最好要结合apache中的错误日志来观察出现何种错误导致出现403错误 下午百度了一下午没找到解决办法,试了n种方法,简直坑爹 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

随机推荐

  1. web开发中,前端javascript代码的组织结构

    网页包含三个层次: 结构(HTML) 表现(CSS) 行为(javascript) web标准中,三者要分离,网页源代码由三部分组成:.html文件..css文件和.js文件.就是说html文件中不应 ...

  2. WPF自定义控件(一)——Button

    接触WPF也有两个多月了,有了一定的理论基础和项目经验,现在打算写一个系列,做出来一个WPF的控件库.一方面可以加强自己的水平,另一方面可以给正在学习WPF的同行一个参考.本人水平有限,难免有一些错误 ...

  3. Git 设置别名[alias]

    工作中我经常设置一下别名... 别名就在[alias]后面,要删除别名,直接把对应的行删掉即可. 而当前用户的Git配置文件放在用户主目录下的一个隐藏文件.gitconfig中: $ cat .git ...

  4. hdu 1496 Equations

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 Equations Description Consider equations having ...

  5. Java之NIO传输数据

    NIO可谓陈词旧调,不值一提. 但之前都是泛泛而谈, 现在深入应用才知道秘诀所在. 对于SocketChannel有read()与write(),但由于"非阻塞IO"本质, 这二个 ...

  6. Effective Objective-C 2.0之Note.03(属性详解)

    用Objective-C等面向对象语言编程时,“对象”(object)就是“基本构造单元”(building block),开发者可以通过对象来存储并传递数据.在对象之间传递数据并执行任务的过程就叫做 ...

  7. NSKeyValueObserving(KVO)

    NSKeyValueObserving非正式协议定义了一种机制,它允许对象去监听其它对象的某个属性的修改. 我们可以监听一个对象的属性,包括简单属性,一对一的关系,和一对多的关系.一对多关系的监听者会 ...

  8. [转]coredump简介与coredump原因总结

    [转]coredump简介与coredump原因总结 http://blog.sina.com.cn/s/blog_54f82cc201013srb.html 什么是coredump? 通常情况下co ...

  9. SVN基于一个branch创建新branch

    在本地现有Branch(Checkout出来的目录)上,右键SVN,选择Branch/Tags,选择目录.比如https://sadcsc01.pmmr.com/web/Jaguar/branches ...

  10. 3-附1 ->和*的区别

    问题: c++ .和 ->有什么区别? 还有什么是继承什么是派生?-------------------------------------------------------------- 比 ...