HDU - 3664 Permutation Counting 排列规律dp
Permutation Counting
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的更多相关文章
- hdu 3664 Permutation Counting(水DP)
Permutation Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 3664 Permutation Counting (DP)
题意:给一个 n,求在 n 的所有排列中,恰好有 k 个数a[i] > i 的个数. 析:很明显是DP,搞了好久才搞出来,觉得自己DP,实在是太low了,思路是这样的. dp[i][j]表示 i ...
- HDU - 3664 Permutation Counting
Discription Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of ...
- hdu3664 Permutation Counting(dp)
hdu3664 Permutation Counting 题目传送门 题意: 在一个序列中,如果有k个数满足a[i]>i:那么这个序列的E值为k,问你 在n的全排列中,有多少个排列是恰好是E值为 ...
- HDU 6880 Permutation Counting dp
题意: 给你一个n和一个长度为n-1的由0/1构成的b序列 你需要从[1,n]中构造出来一个满足b序列的序列 我们设使用[1,n]构成的序列为a,那么如果ai>ai+1,那么bi=1,否则bi= ...
- HDU 3811 Permutation 状压dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...
- HDU3664 Permutation Counting
Permutation Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
随机推荐
- toggle不支持事件代理的解决办法或者 jquery live绑定toggle
$(".xxx").live("click", function () { $(this).toggle(function () {},functio ...
- Linux就该这么学--了解Shell脚本
有人曾经将Shell形容是人与计算机硬件的“翻译官”,Shell作为用户与Linux系统通讯的媒介.自身也定义了各种变量和参数,并提供了诸如循环.分支等高级语言才有的控制结构特性.如何正确的使用这些功 ...
- IDEA tomcat三步实现热部署
IDEA tomcat三步实现热部署 添加Artifacts选项 添加Artifacts选项,XXXwar 和 XXXwar exploded二选一,若要热部署须选后者. 设置tomcat部署方案 设 ...
- flask的请求上下文源码解读
一.flask请求上下文源码解读 通过上篇源码分析( ---Flask中的CBV和上下文管理--- ),我们知道了有请求发来的时候就执行了app(Flask的实例化对象)的__call__方法,而__ ...
- Java多线程系列 基础篇02 线程的创建和运行
1.线程创建的方式常用有两种 1. 继承 Thread 类创建线程 2. 实现 Runnable 接口创建线程 2.Thread 和 Runnable的区别 Thread和Runnable的相同点:都 ...
- ajax 异步 跨域上传图片
客户端 <label for="text">名称</label> <input type="text" id="text ...
- 项目发布之后 总提示有一个.DLL找不到或不匹配
最近发布项目(.net,winform)总提示有一个.dll文件找不到或者不匹配 但是在本地调试是正常的 这个.dll,原来是从.net组件中引用到项目的,后来我将此.dll文件从网上下载,然后在项目 ...
- 如何使用安信可 ESP 系列一体化开发环境【转】
本文转载自:http://wiki.ai-thinker.com/ai_ide_use 关于 Problems 报错 注意:Eclipse 只是一个代码编写工具,它并不能读取 makefile 里面的 ...
- 算法(Algorithms)第4版 练习 1.3.219
方法实现: //1.3.19 /** * remove the last node in the linked list whose first node is first * * @return r ...
- Contiki 2.7 Makefile 文件(一)
一.主控Makefile 这里以hello-world例子为主线,从其工程Makefile开始,解析整个build过程.