Uva 11077 Find the Permutations [置换群 DP]
题意:
给定$n$和$k$,问有多少排列交换$k$次能变成升序
$n \le 21$
$uva$貌似挂掉了$vjudge$上一直排队
从某个排列到$1,2,...,n$和从$1,2,...,n$到某个排列是一样的
排列就是置换,分解循环,然后显然每个循环变成升序需要$len-1$次交换
然后有$t$个循环的置换需要$n-t$次交换
$DP$就行了$f[i][j]$表示前$i$个数有$j$个循环
其实可以发现就是第一类$stirling$数
注意:以后一定要测一遍极限会爆$long\ long$
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=;
typedef unsigned long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,k;
ll f[N][N];
void dp(){
f[][]=;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
f[i][j]=f[i-][j-]+f[i-][j]*(i-);
}
int main(){
//freopen("in","r",stdin);
dp();
while(true){
n=read();k=read();
if(n==&&k==) break;
printf("%llu\n",f[n][n-k]);
}
}
Uva 11077 Find the Permutations [置换群 DP]的更多相关文章
- UVa 11077 Find the Permutations (计数DP)
题意:给定 n 和 m,问你在 1 ~ n 的所有排列中,有多少个排列满足至少要交换 m 次才能变成 1 2 3 ... n. 析:首先,先考虑一下,某个排列,要变成 1 2 3 .. n,最少要交换 ...
- UVA 11077 - Find the Permutations(递推)
UVA 11077 - Find the Permutations option=com_onlinejudge&Itemid=8&page=show_problem&cate ...
- UVA 11077 Find the Permutations 递推置换
Find the Permutations Sorting is one of the most used operations in real ...
- UVA - 11077 Find the Permutations (置换)
Sorting is one of the most usedoperations in real life, where Computer Science comes into act. It is ...
- UVa 11077 Find the Permutations(置换+递推)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35431 [思路] 置换+递推 将一个排列看作一个置换,分解为k个循 ...
- UVA 10163 Storage Keepers(两次DP)
UVA 10163 Storage Keepers(两次DP) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Ite ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- UVA - 825Walking on the Safe Side(dp)
id=19217">称号: UVA - 825Walking on the Safe Side(dp) 题目大意:给出一个n * m的矩阵.起点是1 * 1,终点是n * m.这个矩阵 ...
- LA 3641 Leonardo的笔记本 & UVA 11077 排列统计
LA 3641 Leonardo的笔记本 题目 给出26个大写字母的置换B,问是否存在要给置换A,使得 \(A^2 = B\) 分析 将A分解为几个循环,可以观察经过乘积运算得到\(A^2\)后,循环 ...
随机推荐
- 搭建ruby环境
- win10清除桌面快捷方式小箭头
reg add /d "%systemroot%\system32\imageres.dll,197" /t reg_sz /f taskkill /f /im explorer. ...
- Google PageSpeed Tools 性能测试分析
今天给大家介绍下一个工具:Google PageSpeed Tools,根据官方的介绍,简单梳理如下: Page Speed Insights能针对移动设备和电脑设备衡量网页的性能.该工具会抓取网址两 ...
- 关于Swing窗体有时候要放大缩小边框才能显示问题?
有时候会出现编写swing窗体后添加的组件在run之后显示不出来的问题.如图: 搜了下解决办法.此时如果是程序里面有panel组件的话,应该这样: labels[i] = new Label(lett ...
- windows下更改mysql数据储存物理目录
windows10 1.停止mysql服务 以管理员身份运行cmd 输入命令 net stop mysql57 (我的mysql版本是5.7的,具体名称以你当前版本为主) 也可以打开任务管理器找到上面 ...
- DTD约束
DTD约束 一,导入DTD方式 二,DTD语法 2)DTD语法 约束标签 <!ELEMENT 元素名称类别>或<!ELEMENT 元素名称(元素内容)> 类别: 空标签: ...
- AVFrame转换到Mat,yuv420p转换到RGB源代码
FFmpeg中AVFrame到OpenCV中Mat的两种转换方法 方法一:查表法 void AVFrame2Img(AVFrame *pFrame, cv::Mat& img) { int f ...
- jquery ui-----弹出窗口 dialog
jquery ui 提供了强大的dialog功能,基本能满足开发的功能. 先上一个简单的例子: [代码] <script> $(function() { $( "#dialo ...
- IO 异常:The Network Adapter could not establish the connection 怎么解决
IO 异常:The Network Adapter could not establish the connection 怎么解决
- MyCat 启蒙:分布式系统的数据库架构演变
文章首发于[博客园-陈树义],点击跳转到原文<MyCat 启蒙:分布式系统的数据库架构演变> 单数据库架构 一个项目在初期的时候,为了尽可能快地验证市场,其对业务系统的最大要求是快速实现. ...