Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [l, r] (1 ≤ l ≤ r ≤ m). Interval [l1, r1] belongs to interval [l2, r2] if the following condition is met: l2 ≤ l1 ≤ r1 ≤ r2.

Sereja wants to write out a sequence of n intervals [l1, r1], [l2, r2], ..., [ln, rn] on a piece of paper. At that, no interval in the sequence can belong to some other interval of the sequence. Also, Sereja loves number x very much and he wants some (at least one) interval in the sequence to have li = x. Sereja wonders, how many distinct ways to write such intervals are there?

Help Sereja and find the required number of ways modulo 1000000007 (109 + 7).

Two ways are considered distinct if there is such j (1 ≤ j ≤ n), that the j-th intervals in two corresponding sequences are not equal.

Input

The first line contains integers n, m, x (1 ≤ n·m ≤ 100000, 1 ≤ x ≤ m) — the number of segments in the sequence, the constraints on the numbers in segments and Sereja's favourite number.

Output

In a single line print the answer modulo 1000000007 (109 + 7).

Examples

Input
1 1 1
Output
1
Input
3 5 1
Output
240
Input
2 3 3
Output
6

Note

In third example next sequences will be correct: {[1, 1], [3, 3]}, {[1, 2], [3, 3]}, {[2, 2], [3, 3]}, {[3, 3], [1, 1]}, {[3, 3], [2, 2]}, {[3, 3], [1, 2]}.

题意:给定长度为M的数轴,让你选择N个带编号的线段,使得没有线段有包含关系。 给定X,让你至少选择了一个左端点为X的线段。

思路:N<=M;  所以N<sqrt(N*M)<=330; 没有包含关系,那么线段A的左端点大于B的左端点,那么A的右端点也一定大于B的右端点。所以我们可以自己去匹配。只保存当点左端点和右端点个数即可。

用dp[i][j][x]表示前x个点选择了i个左端点,j个右端点,不难得到方程。由于x可能有点大,我们用滚动数组。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const int Mod=1e9+;
int dp[maxn][maxn][];
int main()
{
int N,M,X;
scanf("%d%d%d",&N,&M,&X);
if(N>M) return puts(""),;
dp[][][]=;
rep(k,,M){//位置
rep(i,,min(N,M)){ //左括号
rep(j,,i){ //右括号
int p=k&;
if(k==X){
dp[i][j][p]=;
if(i>j) (dp[i][j][p]+=dp[i-][j][p^])%=Mod; //左
if(i&&j) (dp[i][j][p]+=dp[i-][j-][p^])%=Mod;//左+右
}
else {
dp[i][j][p]=dp[i][j][p^]; //不放
if(i>j) (dp[i][j][p]+=dp[i-][j][p^])%=Mod; //左
if(i&&j) (dp[i][j][p]+=dp[i-][j-][p^])%=Mod;//左+右
if(j) (dp[i][j][p]+=dp[i][j-][p^])%=Mod;//右
}
}
}
}
rep(i,,N) dp[N][N][M&]=1LL*dp[N][N][M&]*i%Mod;
printf("%d\n",dp[N][N][M&]);
return ;
}

CodeForces - 367E:Sereja and Intervals(组合数&&DP)的更多相关文章

  1. CodeForces 367E Sereja and Intervals

    CodeForces 3 67E (109 + 7). Two ways are considered distinct if there is such j(1 ≤ j ≤ n), that the ...

  2. codeforces 341C Iahub and Permutations(组合数dp)

    C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. 【bzoj4517】[Sdoi2016]排列计数 组合数+dp

    题目描述 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 m 个数是稳定的 满足条 ...

  4. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  5. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

  6. [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT)

    [Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i ...

  7. Codeforces Gym 100231L Intervals 数位DP

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, ...

  8. codeforces 425C Sereja and Two Sequences(DP)

    题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...

  9. CodeForces - 314C Sereja and Subsequences (树状数组+dp)

    Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...

随机推荐

  1. 对不队——Alpha冲刺

    第五天  日期:2018/6/20 一. 今日完成任务:专家审稿逻辑的开发 冯晓.马思远:会议网站栏目管理开发,软件功能测试 王爽.彭辉:审稿管理员分稿和稿件查找功能开发,博客撰写 吴琼.郝延婷:更换 ...

  2. android适配各种分辨率的问题

    Android设备屏幕的尺寸是各式各样的,如小米是4英寸的,Xoom平板是10英寸:分辨率也千奇百怪,800×480,960×540等:Android版本的碎片化问题更是萦绕于心,不过在设计应用时可以 ...

  3. Redis的介绍

    REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统. Redis是一个开源的使用ANSI C语言编写.遵守B ...

  4. mac 无法打开xx ,因为无法确认开发者身份

    系统偏好与设置 - 安全性与隐私 - 通用 允许从以下位置下载的应用: 选择 [任何来源],如果没有这个选项,使用终端执行下面的命令: spctl --master-disable (spctl空格 ...

  5. Python解析Wav文件并绘制波形的方法

    资源下载 #本文PDF版下载 Python解析Wav文件并绘制波形的方法 #本文代码下载 Wav波形绘图代码 #本文实例音频文件night.wav下载 音频文件下载 (石进-夜的钢琴曲) 前言 在现在 ...

  6. spfa毒瘤算法

    终于知道怎么卡spfa(不优化)这一毒瘤算法了 下面就是造数据代码,点数才1e5,边数379980 随便测了一组数据: count: 831841219(入队次数) 68917.096 ms(足够t到 ...

  7. 转 解决linux下tomcat的shutdown命令杀不死进程

    tomcat在windows下可以直接关闭,但是貌似在Linux下有时候shutdown.sh 没有关闭tomcat进程; 现象:在Linux下shutdown.sh ,然后查看tomcat进程发现没 ...

  8. 关于二级指针的使用(使用node指针建树)

    struct node { int v; node *l,*r; }*p; 使用二级指针建树的话,如果p是非全局变量且一开始没有指向变量的话递归建树时必然要传递参数,但是如果只是简单的build(no ...

  9. 无法打开物理文件“E:\Database\VRVIES6841-FZ01-Global\VRVEIS.mdf”。操作系统错误 5:“5(拒绝访问。)”

    在用SQLServer2012附加SQLServer2000备份的数据库事,报如下错误: 无法打开物理文件“E:\Database\VRVIES6841-FZ01-Global\VRVEIS.mdf” ...

  10. 所谓的规范以及JDK api文档的重要性

    所谓的规范,就是在jee api 文档里对应的接口. 可以从jdk文档和jee文档的目录结构,接口中获取对整个编程范围的把握