cf 403 D
3 seconds
256 megabytes
standard input
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).
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).
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.
6
1 1
2 1
2 2
3 1
3 2
3 3
1
3
0
6
2
0
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的更多相关文章
- 【题解】CF#403 D-Beautiful Pairs of Numbers
这题还挺对胃口的哈哈~是喜欢的画风!回家路上一边听歌一边想到的解法,写出来记录一下…… 首先,由于 \(b_{k} < a_{k + 1}\) ,所以我们可以看作是在一个长度为 n 的序列上选择 ...
- Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...
- 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 ...
- apache httpd服务器403 forbidden的问题
一.问题描述 在apache2的httpd配置中,很多情况都会出现403. 刚安装好httpd服务,当然是不会有403的问题了.主要是修改了一些配置后出现,问题描述如下: 修改了DocumentRoo ...
- 遇到 HTTP 错误 403.14 - Forbidden?
打开 http://localhost:1609 报错: HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容 解决方案一:设置默认首页 在 Web.conf ...
- nginx 访问目录403
centos7.2默认安装好nginx后,会在/usr/share/nginx/html下作为主目录 但是如果想访问下面的目录会发现没有权限,返回403错误 这时候要注意在/etc/nginx/ngi ...
- Apache2.4部署django出现403 Forbidden错误解决办法
前言:Apache2.4部署django出现403 Forbidden错误最好要结合apache中的错误日志来观察出现何种错误导致出现403错误 下午百度了一下午没找到解决办法,试了n种方法,简直坑爹 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
随机推荐
- EMVTag系列12《卡片内部风险管理数据》
Ø 9F53 连续脱机交易限制数(国际-货币) L: 1 -C(有条件):如果执行国际-货币频度检查 PBOC专有数据元. 不使用指定应用货币的连续脱机交易次数最大数,超过后交易请求联机 模板 ...
- [INS-41112] Specified network interface doesnt maintain connectivi
OS: Oracle Linux Server release 6.3 DB: Oracle 11.2.0.3 安装11.2.0.3.0的RAC,在安装GRID时报错: [INS-41112] Spe ...
- [Environment Build] Maven环境配置
1. 下载并解压maven文件 2. 在环境变量中配置一个JAVA_HOME的变量,指向你本地的JDK 3. 在系统变量中新建一个名为:MAVEN_HOME的变量,指向你的maven解压文件的bin目 ...
- SystemServer相关
SystemServer分析 由Zygote通过Zygote.forkSystemServer函数fork出来的.此函数是一个JNI函数,实现在dalvik_system_Zygote.c中. 1.S ...
- ubuntu14.04字符界面中文乱码及中文输入
作为ubuntu用户字符界面是绝对不陌生的,尤其是维护管理服务器的朋友为了节省资源都是用的字符界面,但是默认字符界面中文目录文件都是乱码,根本无法打开编辑,那么怎么让字符界面显示中文目录文件,还有在字 ...
- 纯真IP数据库导入mysql
下载纯真IP数据库 安装后解压到本地为ip.txt 格式为: 1.1.145.0 1.1.147.255 泰国 沙功那空 1.1.148.0 1.1.149.255 ...
- Objective-C-实例变量与属性的关系
当在一个类创建一个属性,Xcode编译器就会自动产生一个带下划线的同名实例变量: 一般来说,如果getter这个属性采用下划线的方式获取效率更高,而setter采用self.属性名更加合理. 读取实例 ...
- Ant学习---第二节:Ant添加文件夹和文件夹集的使用
一.创建 java 项目(Eclipse 中),结构图如下: 1.创建 .java 文件,代码如下: package com.learn.ant; public class HelloWorld { ...
- 格式化输出[part1/标准控制符]
/* 设置输出字符的宽度 width(int)是iostream类的成员函数,可以通过cout对象来调用,即cout.width(int) 注: 1.width(int)只影响将要显示的一个对象,之后 ...
- Android -- 分享功能和打开指定程序
打开指定程序 Intent intent ...