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(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
随机推荐
- C 构造一个 简单配置文件读取库
前言 最近看到这篇文章, json引擎性能对比报告 http://www.oschina.net/news/61942/cpp-json-compare?utm_source=tuicool 感觉技术 ...
- .NET开源工作流RoadFlow-流程设计-流程步骤设置-按钮设置
按钮设置是配置当前步骤的处理者可以执行哪些操作,每个按钮都有对应的执行脚本(javascript脚本). 从左边的按钮列表中选择当前步骤需要的按钮. 注意:如果是流程最后一步则要配置完成按钮而不是发送 ...
- 2015 年开源前端框架盘点 TOP 20
1.名称:Bootstrap 类别/语言:HTML.CSS.JavaScript 创建者: Twitter 人气:在Github上有91007 stars 描述:主流框架中毋庸置疑的老大,Bootst ...
- ios中三种多线程的技术对比
1.NSThread 使用较少 在NSThread调用的方法中,同样要使用autoreleasepool进行内存管理,否则容易出现内存泄露. 使用流程:创建线程-->启动线程 2.NSOpera ...
- C++ json库jsoncpp 吐槽
Explain 最近在做游戏接入SDK时用到C++的json库jsoncpp,jsoncpp 是一款优秀的json库,但恶心的一点是它采用Assert作为错误处理方法,而assert在linux下通过 ...
- 安装Ubuntu 15.10后要做的事
Ubuntu 15.10发布了,带来了很多新特性,同样也依然带着很多不习惯的东西,所以装完系统后还要进行一系列的优化. 1.删除libreoffice libreoffice虽然是开源的,但是Java ...
- b75,gtx560,I5 安装10.10.2
1.安装变色龙,wowpc.iso,这个是可以让电脑从windows引导 mac 安装的. 2.把黑苹果CDR压到一个硬盘分区里去. 3.安装10.10.2,把安装盘里的extra拷贝到 系统盘里 , ...
- c语言的结构体字节数统计
struct结构体的字节数 等于 结构体中最大类型的字节数的倍数. 如: typedef struct Student{ short id; //2个字节 char name[15]; / ...
- 55.ERROR:Place:1136 - This design contains a global buffer instance…… non-clock load pins off chip
ISE在布局布线时,出现下图所示错误. 对于"clock_dedicated_route”错误原因有两种情况: 1. 就是有一个时钟你没有放到全局时钟或者局部时钟的引脚,布局的时候不能把它 ...
- jQuery4ajax
1.jQuery对ajax编程的支持 (1)load方法: 作用:将服务器返回的数据直接添加到符合要求的dom节点之上. 用法:load(url,[data]); url:请求地址,比如"p ...