Permutation Counting
\(n\) 的范围很小,考虑动态规划。
\(f_{i,j}\) 在前 \(i\) 个数有 \(j\) 个 \(<\) 的个数。
若 \(\texttt {a<b<c<d}\),且有序列 \(a<c>b\)。
若在 \(a\) 之前插入 \(d\),则变为 \(d>a<c>b\),\(<\) 个数不变。
若在 \(a<c\) 之间插入 \(d\),则变为 \(a<d>c>b\),\(<\) 个数不变。
若在 \(c>b\) 之间插入 \(d\),则变为 \(a<c<d>b\),\(<\) 个数加一。
若在 \(b\) 之后插入 \(d\),则变为 \(a<c>b<d\),\(<\) 个数加一。
所以在序列头部,\(<\) 号处加入,\(<\) 总个数不变。在序列尾部,\(>\) 号处加入,\(<\) 总个数加一。
可得转移方程:f[i][j]=(f[i-1][j]*(j+1)+f[i-1][j-1]*(i-j))。
即若 \(<\) 不增加 \(f_{i,j}=f_{i-1,j}\times ( \text{原} < \text{的个数} + \text{开头的位置})\)。
若增加 f[i][j]=f[i-1][j-1]*((i-1)-(j-1)-1+1); \(i-1\) 为数字个数,\(j-1\) 为 \(<\) 号个数,数字个数减一就是符号的个数,减去 \(<\) 号个数即为 \(>\) 号个数,最后还要在加上序列末尾的 \(1\)。所以最后变为 f[i-1][j-1]*(i-j)。
代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1007;
const int mod=1e9+7;
long long f[N][N];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
for(int i=1;i<N;i++){
f[i][0]=1;
for(int j=1;j<N;j++){
f[i][j]=(f[i-1][j]*(j+1)+f[i-1][j-1]*(i-j))%mod;
}
}
int a,b;
while(cin>>a>>b) cout<<f[a][b]<<'\n';
return 0;
}
Permutation Counting的更多相关文章
- hdu 3664 Permutation Counting(水DP)
Permutation Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU3664 Permutation Counting
Permutation Counting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU - 3664 Permutation Counting 排列规律dp
Permutation Counting Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the ...
- hdu3664 Permutation Counting(dp)
hdu3664 Permutation Counting 题目传送门 题意: 在一个序列中,如果有k个数满足a[i]>i:那么这个序列的E值为k,问你 在n的全排列中,有多少个排列是恰好是E值为 ...
- H. Permutation Counting 判环,计数,拓扑
H. Permutation Counting 2022/7/28 传送门:https://codeforces.com/group/5zHJ4CTyoU/contest/392060/problem ...
- HDU - 3664 Permutation Counting
Discription Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-value as the amount of ...
- HDU 3664 Permutation Counting (DP)
题意:给一个 n,求在 n 的所有排列中,恰好有 k 个数a[i] > i 的个数. 析:很明显是DP,搞了好久才搞出来,觉得自己DP,实在是太low了,思路是这样的. dp[i][j]表示 i ...
- HDU 6880 Permutation Counting dp
题意: 给你一个n和一个长度为n-1的由0/1构成的b序列 你需要从[1,n]中构造出来一个满足b序列的序列 我们设使用[1,n]构成的序列为a,那么如果ai>ai+1,那么bi=1,否则bi= ...
- UVALive 5971
Problem J Permutation Counting Dexter considers a permutation of first N natural numbers good if it ...
- LeetCode_Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
随机推荐
- Oracle客户端中文显示问号乱码问题
Oracle显示中文显示??乱码 问题如下图 解决方法 打开Oracle客户端,新建一个SQL Window 输入select userenv('language') from dual 复制搜索到的 ...
- helm Error: INSTALLATION FAILED: cannot re-use a name that is still in use
前言 使用helm安装服务报错,修改chat后重新安装报错:安装失败:无法重复使用仍在使用的名称 解决方法 1.查找安装失败的服务 helm -n {namespace} ls -a 2.删除安装失败 ...
- npm ERR! request to https://registry.npm.taobao.org/axios failed, reason: certificate has expired
前言 一直使用 npm build没问题的,突然出现报错: npm WARN install Usage of the `--dev` option is deprecated. Use `--onl ...
- openssl基础使用(密码学 linux)
目录 实验原理 实验过程 一.对称加密 1.使用rc4加解密 2.使用AES加解密 ...
- ESX与ESXi区别
VMware ESXi 与ESX 产品之比较 VMware vSphere 5.0 以后版本,所有底层虚拟化产品都改为ESXi产品,本文主要比较了ESXi与ESX的各自特点,以便对大家是否要把现有的E ...
- Shader作画
代码运行网站:http://editor.thebookofshaders.com/ // Author @CuriosityWang // https://www.cnblogs.com/curio ...
- 【Python自动化测试环境管理】tox
1. tox基本介绍 1.1 tox是什么? tox 是一个用于管理 Python 项目的自动化测试和环境管理工具.它的主要功能是创建虚拟环境并运行项目的测试套件,tox能够让我们在同一个Host上自 ...
- 【教程】Windows10系统激活
Windows10系统激活 一.找一个激活码 到百度搜索,筛选发表日期在最近一个月或者一周之内的 二.以管理员身份打开cmd 按Win+R键,输入cmd打开命令行窗口 按Ctrl+Shift+Esc键 ...
- AIR780E引脚复用笔记
1.应用场景: 使用AIR780E模块驱动TM1637数码管驱动芯片,原有方案是AIR724UG+TM1637.为了降低成本,按照官方方案进行代码迁移. 伴随着代码迁移,硬件引脚也需要做相应调 ...
- Rubymine搭建Ruby开发环境
1.下载和安装Ruby 下载链接:https://rubyinstaller.org/downloads/ 安装示意图: 注意勾选图示的两个选项 安装完成后在cmd窗口运行:ruby -v命令显示当前 ...