这题还挺对胃口的哈哈~是喜欢的画风!回家路上一边听歌一边想到的解法,写出来记录一下……

 首先,由于 \(b_{k} < a_{k + 1}\) ,所以我们可以看作是在一个长度为 n 的序列上选择出 k 个不相交的区间使得这 k个区间的长度各不相同。那么我们可以先求出 \(f[i][j]\) 表示选择了 \(i\) 个区间,这 \(i\) 个区间的区间长度总和为 \(j\) 的方案数。然后,我们考虑用这些方案数与序列剩下的长度的划分的方案数共同构成答案。所以我们再求一个 \(g[i][j]\) 表示将 \(j\) 的长度划分成可空的 \(i\) 段的方案数。答案 \(h[k][n]\) 表示在长为 n 的序列上选出了 \(k\) 个不相交,各不相同的区间的方案数。有了 \(f,g\)数组,我们只需要枚举一下选择的区间总长 i,将 \(f[k][i] * g[k + 2][n - i]\) 加到答案中即可。

  但是,这样做不是 \(1000^{3}\) 的的吗?实际上,k 的取值范围远不可能到达 1000。由于区间的长度各不相同,我们不难求出当 \(k >= 45\) 的时候答案为 0,并不需要计算。这样,我们就可以在优秀的 \(5e7\) 的复杂度下通过此题~

#include <bits/stdc++.h>
using namespace std;
#define maxn 1010
#define maxm 100000
#define maxk 50
#define mod 1000000007
#define int long long
int N = , lim = , h[maxn][maxn];
int t[][maxk][maxn], f[maxk][maxn], g[maxk][maxn];
int fac[maxm], inv[maxm]; int read()
{
int x = , k = ;
char c; c = getchar();
while(c < '' || c > '') { if(c == '-') k = -; c = getchar(); }
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * k;
} int C(int n, int m)
{
if(n < m || n < || m < ) return ;
return fac[n] * inv[m] % mod * inv[n - m] % mod;
} void pre()
{
fac[] = ; inv[] = inv[] = ;
for(int i = ; i < maxm; i ++) fac[i] = fac[i - ] * i % mod;
for(int i = ; i < maxm; i ++) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
for(int i = ; i < maxm; i ++) inv[i] = inv[i - ] * inv[i] % mod;
} void Up(int &x, int y) { x = x + y; if(x >= mod) x -= mod; }
void Work()
{
int pre = , now = ; t[pre][][] = ;
for(int i = ; i <= N; i ++)
{
memset(t[now], , sizeof(t[now]));
for(int k = ; k <= lim; k ++)
for(int j = ; j <= N; j ++)
{
t[now][k][j] = t[pre][k][j];
if(k && j - i >= ) Up(t[now][k][j], t[pre][k - ][j - i]);
}
swap(pre, now);
}
for(int i = ; i <= lim; i ++)
for(int j = ; j <= N; j ++)
f[i][j] = t[pre][i][j] * fac[i] % mod;
for(int i = ; i <= lim; i ++) g[i][] = ;
for(int i = ; i <= lim; i ++)
for(int j = ; j <= N; j ++)
g[i][j] = C(i + j - , j); for(int i = ; i <= lim; i ++)
for(int j = ; j < N; j ++)
{
int ret = ;
for(int k = ; k <= j; k ++)
Up(ret, f[i][k] * g[i + ][j - k] % mod);
h[i][j] = ret;
}
} signed main()
{
pre(); Work(); int T = read();
while(T --)
{
int n = read(), K = read();
if(K <= lim) printf("%I64d\n", h[K][n]);
else printf("0\n");
}
return ;
}

【题解】CF#403 D-Beautiful Pairs of Numbers的更多相关文章

  1. CF 403D Beautiful Pairs of Numbers

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

  2. [CF403D]Beautiful Pairs of Numbers

    题意:给定$n,k$,对于整数对序列$\left(a_1,b_1\right),\cdots,\left(a_k,b_k\right)$,如果$1\leq a_1\leq b_1\lt a_2\leq ...

  3. Codeforces 403D: Beautiful Pairs of Numbers(DP)

    题意:转换模型之后,就是1~n个数中选k个,放到一个容量为n的背包中,这个背包还特别神奇,相同的物品摆放的位置不同时,算不同的放法(想象背包空间就是一个长度为n的数组,然后容量为1的物体放一个格子,容 ...

  4. cf 403 D

    D. Beautiful Pairs of Numbers time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  5. CF 55 D. Beautiful numbers

    D. Beautiful numbers 链接 题意: 求[L,R]中多少个数字可以整除它们的每一位上的数字. 分析: 要求模一些数字等于0等价于模它们的lcm等于0,所以可以记录当前出现的数字的lc ...

  6. Codeforces CF#628 Education 8 D. Magic Numbers

    D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  8. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

    还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...

  9. 【题解】 Codeforces 919F A Game With Numbers(拓扑排序+博弈论+哈希)

    懒得复制,戳我戳我 Solution: 我感觉我也说不太好,看Awson的题解吧. 说一点之前打错的地方: 连边存的是hash后的数组下标 if(ans[ num( C[a.hash()] , C[b ...

随机推荐

  1. CLR via c#读书笔记六:参数

    注:书本第9单参数 CLR默认所有方法参数都传值.引用本身是值引的,意味左方法能修改对象,而调用都能看到这些修改.值类型,传的是实例的一个副本,所以调用者不受影响. (和以前理解的不一样.默认都是传值 ...

  2. STM32的System memory

    Main Flash memory 是STM32内置的Flash,一般我们使用JTAG或者SWD模式下载程序时,就是下载到这个里面,重启后也直接从这启动程序. System memory 从系统存储器 ...

  3. 解决CentOS下可以ping通ip ping不通域名

    现象:1. ping不通域名,比如 www.qq.com 2. 可以ping通ip,比如 61.135.157.156 分析:1. 查看DNS配置文件 /etc/resolve.conf, 里面的服务 ...

  4. How To Install Apache Tomcat 7 on CentOS 7 via Yum

    摘自:https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-7-on-centos-7-via-y ...

  5. C#原型模式

    如下: [Serializable] public class ModelNewTable : ICloneable { public object Clone() { using (var stre ...

  6. CentOS安装nmon

    nmon官网: http://nmon.sourceforge.net/pmwiki.php?n=Main.HomePage 下载nmon16e_mpginc.tar.gz到本地并上传到服务器 tar ...

  7. 打印队列 (Printer Queue,ACM/ICPC NWERC 2006,UVA12100)

    题目描述: 题目思路: 使用一个队列记录数字,一个优先队列记录优先级,如果相等即可打印: #include <iostream> #include <queue> using ...

  8. (转) GEM透视阴影贴图

    转载:小道 透视阴影贴图(Perspective Shadow Maps, PSMs)是由Stamminger和Drettakis在 SIGGRAPH 2002上提出的一种阴影贴图(Shadow Ma ...

  9. HDU 1250 Hat's Fibonacci(高精度)

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  10. windows远程连接失败问题排查思路

    一般情况下,对WIN7的远程连接只需要5步即可完成远程连接的设置: 1).用户是否设置了密码 2).计算机属性-允许远程登录 3).设置计算机永不睡眠 4).关闭防火墙或者设置入站规则 5).排查Re ...