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. String类详解,StringBuffer

    先说一下String类的equals()方法. 下面我们先看一段代码: 这段代码输出的结果为: ture true -------------- false 咋看之下貌似Object类比较特别,那么我 ...

  2. Linux下mysql自动备份

    #!/bin/bashDATE=`date +%Y-%m-%d-%H:%M -d -3minute`USER=rootPASSWORD=mayboBACKUP_DIR='/home/mysqlbak/ ...

  3. Java动态替换InetAddress中DNS的做法简单分析2

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.i ...

  4. [转]ubuntu server上网配置

    [转]ubuntu server上网配置 http://blog.sina.com.cn/s/blog_6c9d65a101011pyt.html 今天我的ubuntu server上不去网了,所以重 ...

  5. StatusBar & StatusBarItem

    StatusBar & StatusBarItem StatusBar StatusBar class StatusBarItem StatusBarItem class Example &l ...

  6. Jquery 1.8.2 click function - 动态

    Jquery 动态按钮方法如下:   $("#parentID").on("click",'.classname',function(){$(this).par ...

  7. Ubuntu 12.04 Desktop配置XAMPP【转】

    转载:[ubuntu][xampp]开发环境配置 XAMPP 并不适用于生产环境,而仅供开发环境使用.XAMPP 被设置为尽量开放,并提供开发者任何他/她想要的功能.这对于开发环境来说是很棒的,但对于 ...

  8. 运算符 swift

    1nil聚合运算符 nil coalescing operator a ?? b ==>a!=nil ? a! : b 要求: 1a是一个可选类型 2b必须和a解包后类型一致 var userN ...

  9. plist 读取 swift

    // // ViewController.swift // plist读写 // // Created by mac on 15/7/13. // Copyright (c) 2015年 fangyu ...

  10. OC中数组类NSArray的详解,常用属性和方法(一)

    数组是一个有序的集合,OC中的数组只能存储对象类型, 但是对于对象的类型没有限制. 通过下标访问数组元素,下标从0开始. NSA