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+广搜 使用广度优先 ...
随机推荐
- 线程(while 和 if 剖析)
那存钱取钱为例: 要求实现一次存一次取的操作 不可出现连续存或连续取: 如果只有存钱和取钱各自只有一个线程在操作使用 if 的话可以满足要求: package com.thread; /** * 模拟 ...
- 九度OJ 1151:位操作练习 (位操作)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1679 解决:924 题目描述: 给出两个不大于65535的非负整数,判断其中一个的16位二进制表示形式,是否能由另一个的16位二进制表示形 ...
- Mac下终端常用命令
一.删除文件 1 打开终端应用程序 2 输入命令:sudo (空格) rm (空格)-r (空格)-f (空格)(注意-f后面还有空格),还要注意,全部小写. 3 把你要删的文件或者文件夹用mouse ...
- Java AQS详解(转)
原文地址 一.概述 谈到并发,不得不谈ReentrantLock:而谈到ReentrantLock,不得不谈AbstractQueuedSynchronizer(AQS)! 类如其名,抽象的队列式的同 ...
- 在linux 中卸载Mysql
一.通用的mysql卸载方式 1.查看系统中是否已经安装了mysql 命令:rpm -qa|grep -i mysql如果有显示msql的安装列表,代表已经安装了. 2.停止mysql服务.删除之前安 ...
- 用js实现图片(小球)在屏幕上上下左右移动
<html> <head> <title>Document</title> </head> <body style="bac ...
- JavaScript(4)
myfuns.js //自定义函数 //输入两个数,再输入一个运算符(+,-,*,/),得到结果->函数 function jiSuan(num1,num2,operator){//特别强调 参 ...
- SFTP 文件上传下载引用代码
http://sha1064616837.iteye.com/blog/2036996 http://www.cnblogs.com/itmanxgl/p/fe5d33512609fe540eb08a ...
- cifs挂载远程文件出现 No such device or address错误
1. 参考 https://www.raspberrypi.org/forums/viewtopic.php?t=82199 找了两天看到这个文章才解决了问题. 我是之前同事在windows上挂载成功 ...
- 基于jQuery Ajax实现无刷新文件上传
最近因项目需求更改,需要实现选择文件后即时上传至服务器,然后提交后,加载xls表格内容到jqgrid表格中,文件上传功能实现示例: 前端jsp页面: <form id="uploadF ...