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

 首先,由于 \(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. 13 内建属性 _getattribute_ 内建函数

    1.内建属性 2.__getattribute__ 属性访问时拦截器 class Itcast(object): def __init__(self,subject1): self.subject1 ...

  2. ORB-SLAM(七)ORBextractor 特征提取

    该类中主要调用OpenCV中的函数,提取图像中特征点(关键点及其描述,描述子,以及图像金字塔) 参考TUM1.yaml文件中的参数,每一帧图像共提取1000个特征点,分布在金字塔8层中,层间尺度比例1 ...

  3. spring使用set方法注入的常见类型写法

    首先配置spring的pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...

  4. 「日常训练」Equation(HDU-5937)

    题意与分析 时隔一个月之后来补题.说写掉的肯定会写掉. 题意是这样的:给1~9这些数字,每个数字有\(X_i\)个,问总共能凑成多少个不同的等式\(A+B=C\)(\(A,B,C\)均为1位,\(1+ ...

  5. 【wx:if】小程序条件渲染的使用说明

    语法,以view为例: <view xw:if="{{条件}}">aaaa</view> <view xw:elif="{{条件}}&quo ...

  6. DeepLearning - Forard & Backward Propogation

    In the previous post I go through basic 1-layer Neural Network with sigmoid activation function, inc ...

  7. 吴恩达j机器学习之过拟合

    五.编程作业: 见:https://www.cnblogs.com/tommyngx/p/9933803.html

  8. [leetcode-738-Monotone Increasing Digits]

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...

  9. 《剑指Offer》题三十一~题四十

    三十一.栈的压入.弹出序列 题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的数字均不相等.例如,序列{1, 2, 3, 4 ,5}是某栈的压栈序列 ...

  10. protected、public、private

    一.protected成员 1. 受保护的成员的可访问性 对于一个类的protected成员,①该类的用户(如类对象)不能访问它,②该类的派生类的成员(及其友元)可以访问它. 派生类的成员及其友元不能 ...