Permutation Counting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1739    Accepted Submission(s): 918

Problem Description

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.

Input

There are several test cases, and one line for each case, which contains two integers, N and k. (1 <= N <= 1000, 0 <= k <= N).

Output

Output 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}

Source

2010 Asia Regional Harbin

Recommend

题意  :E条件:就是在下标为i处的数值ai大于i (i从1开始) 给出数串的长度N 与k 问在当下数串长度下1,2,3。。。N 的数串排列中 有多少个排列符合E条件
dp 。。。
d[i][j]=d[i-1][j]+d[i-1][j]*j+d[i-1][j-1]*(i-j);
即 在i长度下每个排列的E条件数为j的排列数  =  当在i-1长度下  有j个E条件的排列数 + 在i-1长度下有j个E条件数的排列数 * (新数来了后与符合条件的数交换 仍然符合E条件)+ 在i-1长度下  有j-1个符合E条件的数的排列数 * (i-j)【即把 每个有j-1个符合的排列中不符合E条件的数与新来的第i个数交换 符合条件的数会++】
也就是说 把直接放后面的 还有与符合条件数交换的 还有不符合条件的数交换的所有情况都考虑在内
code。。。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
ll d[1010][1010];
int main()
{d[1][0]=1;for(int i=1;i<=1000;i++)d[1][i]=0;for(int i=2;i<=1000;i++){for(int j=0;j<=i;j++){d[i][j]=d[i-1][j]+d[i-1][j]*j+d[i-1][j-1]*(i-j);  d[i][j]%=MOD;} } int n,k;while(cin>>n>>k){cout<<d[n][k]<<endl;}return 0;
}
注意结果取模 并且dp数组要开ll

HDU-3664-Permutation Counting相关推荐

  1. HDU 3664 Permutation Counting

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

  2. HDU 3664 Permutation Counting(DP)

    题目链接 弱爆啦,组合弱爆了,反正是没想出来怎么搞这个题,其实这个公式不难推啊,反正就是没推出来.今天队内赛,实在是没办法了,暴力写了个DFS,先把10以内的打出表来,发现类似杨辉三角的一个表,推不出 ...

  3. HDU多校10 - 6880 Permutation Counting(dp+思维)

    题目链接:点击查看 题目大意:给出一个长度为 n - 1 的 01 序列 b 用来表示排列 a 的相对大小关系,b[ i ] = 0 说明 a[ i ] < a[ i + 1 ] ,b[ i ] ...

  4. hdu 3664 1~n排列(aii ) 为k个数

    http://acm.hdu.edu.cn/showproblem.php?pid=3664 求1~n的排列个数,使得逆序数(ai>i ) 为给定的k. dp[i][j]表示前1~i的排列中,有 ...

  5. 后缀数组 --- HDU 3518 Boring counting

    Boring counting Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3518 Mean: 给你一个字符串,求:至少出 ...

  6. HDU 4917 Permutation(拓扑排序 + 状压DP + 组合数)

    题目链接 Permutation 题目大意:给出n,和m个关系,每个关系为ai必须排在bi的前面,求符合要求的n的全排列的个数. 数据规模为n <= 40,m <= 20. 直接状压DP空 ...

  7. 【DP】【Asia - Harbin - 2010/2011】【Permutation Counting】

    [题目描述]Given a permutation a1, a2,...aN of {1, 2,..., N}, we define its E-value as the amount of elem ...

  8. 【HDU - 6184】Counting Stars(三元环计数,二分,优化暴力,O(m*sqrt(m)),图论)

    题干: Little A is an astronomy lover, and he has found that the sky was so beautiful! So he is countin ...

  9. hdu 4345 Permutation

    http://acm.hdu.edu.cn/showproblem.php?pid=4345 记忆化搜索 dp  比赛的时候没想出来呀亲 此题和 置换群有那么丁点关系 但关系不大 题目让我们求的是 实 ...

  10. HDU 1718 Rank counting sort解法

    本题是利用counting sort的思想去解题. 注意本题,好像利用直接排序,然后查找rank是会直接被判WA的.奇怪的推断系统. 由于分数值的范围是0到100,很小,而student 号码又很大, ...

最新文章

  1. pytorch使用empty跟内建函数random_进行初始化Tensor
  2. windows10 安装docker
  3. sublime c 语言 编译环境搭建,详解sublime搭建C/C++编译环境
  4. 东芝硬盘插入台式机后滴滴响
  5. 使用jps来查看虚拟机状态
  6. 每次点击添加css动画,div点击添加css动画
  7. Spring-beans-BeanPostProcessor/InitializingBean
  8. 我的博客园开张了,记录每天学习,工作。
  9. 文本处理三剑客之gawk
  10. c语言文件打开幕式,c语言奥运会开幕式
  11. 阮一峰ES6学习笔记
  12. 使用adb shell screencap命令截图
  13. LoadRunner视频教程
  14. BOOTCAMP U盘安装WIN7一直显示无法创建可引导的USB驱动器
  15. 算法题目打卡:Ques20201019
  16. C,D,Go,Rust,Nim,Zig,V,Julia,Py,C#,Kotlin 11语回文数大战!仅供娱乐参考!
  17. C printf() 详解之终极无惑
  18. iPhone12充电功率多少W
  19. 怎样把多个TXT文件合成为一个TXT文件
  20. 公众号被处罚后排名下滑

热门文章

  1. Qt之Concurrent框架
  2. SQL-Server使用点滴(一-数据对象篇)
  3. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜
  4. C# MVC使用阿里云对象存储加快图片加载速度(一)
  5. Visual.Assist.X.V10.7.1940的汉化破解补丁
  6. CentOS离线安装gcc环境(附安装包+图文并茂)
  7. Linux|CentOS下配置Maven环境
  8. android webView注入js方法
  9. php5.3 sql server,php5.3连接sqlserver2005
  10. Springcloud整理