Permutation Counting

Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of elements where ai > i. For example, the E-value of permutation {1, 3, 2, 4} is 1, while the E-value of {4, 3, 2, 1} is 2. You are requested to find how many permutations of {1, 2, …, N} whose E-value is exactly k.

InputThere are several test cases, and one line for each case, which contains two integers, N and k. (1 <= N <= 1000, 0 <= k <= N). 
OutputOutput one line for each case. For the answer may be quite huge, you need to output the answer module 1,000,000,007.Sample Input

3 0
3 1

Sample Output

1
4

Hint

There is only one permutation with E-value 0: {1,2,3}, and there are four permutations with E-value 1: {1,3,2}, {2,1,3}, {3,1,2}, {3,2,1}

数列1-n,可以随意排列组合,求恰有k个a[i]>i的排列个数。
一道找规律的dp。看数据范围就知道不能暴力求解,但可以用暴力找出n较小的几种小数列排列数,发现规律。类似杨辉三角,就像两数和靠拢,于是可以发现状态转移方程f[i][j]=(((i+1)*f[i][j-1])%MOD+((j-i)*f[i-1][j-1])%MOD)%MOD

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<algorithm>
#include<vector>
#include<iterator>
#define MAX 1005
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std; typedef long long ll; ll f[MAX][MAX]; int main()
{
int n,m,i,j;
for(i=;i<=;i++){
f[][i]=;
}
for(i=;i<=;i++){
for(j=i+;j<=;j++){
f[i][j]=(((i+)*f[i][j-])%MOD+((j-i)*f[i-][j-])%MOD)%MOD;
}
}
while(~scanf("%d%d",&n,&m)){
if(n==m){
printf("0\n");
continue;
}
printf("%lld\n",f[m][n]);
}
return ;
}
 

HDU - 3664 Permutation Counting 排列规律dp的更多相关文章

  1. hdu 3664 Permutation Counting(水DP)

    Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. HDU 3664 Permutation Counting (DP)

    题意:给一个 n,求在 n 的所有排列中,恰好有 k 个数a[i] > i 的个数. 析:很明显是DP,搞了好久才搞出来,觉得自己DP,实在是太low了,思路是这样的. dp[i][j]表示 i ...

  3. HDU - 3664 Permutation Counting

    Discription Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of ...

  4. hdu3664 Permutation Counting(dp)

    hdu3664 Permutation Counting 题目传送门 题意: 在一个序列中,如果有k个数满足a[i]>i:那么这个序列的E值为k,问你 在n的全排列中,有多少个排列是恰好是E值为 ...

  5. HDU 6880 Permutation Counting dp

    题意: 给你一个n和一个长度为n-1的由0/1构成的b序列 你需要从[1,n]中构造出来一个满足b序列的序列 我们设使用[1,n]构成的序列为a,那么如果ai>ai+1,那么bi=1,否则bi= ...

  6. HDU 3811 Permutation 状压dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...

  7. HDU3664 Permutation Counting

    Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. HDU 1003 Max Sum --- 经典DP

    HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...

  9. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

随机推荐

  1. Spring自定义配置--ConfigurationProperties

    自定义配置的变量名: 在 *.properties 里面定义特定的变量 server.port=9000 amazon.associateId=habuma-20 建立Properties文件制定特定 ...

  2. Swift 烧脑体操(一) - Optional 的嵌套

    前言 Swift 其实比 Objective-C 复杂很多,相对于出生于上世纪 80 年代的 Objective-C 来说,Swift 融入了大量新特性.这也使得我们学习掌握这门语言变得相对来说更加困 ...

  3. vs2012环境配置

    快捷键 css格式设置 字体设置 新建项目 项目创建失败? 更改默认开发语言环境 1.快捷键 代码格式化:Ctrl+K+D 2.css格式设置: 工具→选项→文本编辑器→CSS→格式设置→选择“紧凑模 ...

  4. jzyz集训 0611

    今天jjh和mzx搞的互测题目有必要记录一下. T1:序列上可以放012三种颜色,有m个限制表示[l,r]区间的颜色数目必须是c,求方案数. 显然的DP,但关键是状态怎么设置,连续设置了n个状态都被自 ...

  5. 在WAMPSERVER下增加多版本的PHP(PHP5.3,PHP5.4,PHP5.5 ,PHP5.6)支持。

    本人预装了一个wamp的集成环境(Apache 2.4.9 + PHP 5.5.12 + mysql 5.6.17),今天在wamp环境下 添加PHP多版本 (PHP 5.5.30).中间两个过程,1 ...

  6. SQL 数据类型 numeric varchar char

    Numeric(10,2) 指字段是数字型,长度为10 小数为两位的 简要描述一下SQL中的五种数据类型:字符型,文本型,数值型,逻辑型和日期型 字符型 VARCHAR VS CHAR VARCHAR ...

  7. Spring Boot2.0之web开发

    1.关于静态资源的访问 在我们开发Web应用的时候,需要引用大量的js.css.图片等静态资源. Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则: /s ...

  8. 如何在Mac的Finder中显示/usr、/tmp、/var等隐藏目录

    原文链接: http://blog.csdn.net/yhawaii/article/details/7435918 Finder中默认是不显示/usr./tmp./var等隐藏目录的,通过在终端中输 ...

  9. 使用meld作为git的辅助工具

    原文链接: https://lrita.github.io/2017/05/14/use-meld-as-git-tool/?hmsr=toutiao.io&utm_medium=toutia ...

  10. chrome浏览器常用快捷键

    chrome浏览器常用快捷键 一.总结 一句话总结: Ctrl + j:打开“下载内容”页 Ctrl + t:打开新的标签页,并跳转到该标签页 Ctrl + d:将当前网页保存为书签 1.在新标签页中 ...