UVa 11077 Find the Permutations(置换+递推)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35431
【思路】
置换+递推
将一个排列看作一个置换,分解为k个循环,则最少需要n-k次交换(循环内部交换)即可排序。
设f[i][j]表示将i个数至少交换j次排序完成的方案数,则有转移方程:
f[i][j] = f[i-1][j]+(i-1)*f[i-1][j-1]
分别表示独立成为一个循环与加入前i-1个循环。
【代码】
#include<cstdio>
#include<cstring>
using namespace std; typedef unsigned long long LL;
const int N = 30+5; LL f[N][N];
int n,k; int main() {
f[1][0]=1;
for(int i=2;i<=21;i++)
for(int j=0;j<i;j++) {
f[i][j]=f[i-1][j];
if(j) f[i][j] += (i-1)*f[i-1][j-1];
}
while(scanf("%d%d",&n,&k)==2 && (n||k))
printf("%llu\n",f[n][k]);
return 0;
}
UVa 11077 Find the Permutations(置换+递推)的更多相关文章
- 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(递推)
UVA 11077 - Find the Permutations option=com_onlinejudge&Itemid=8&page=show_problem&cate ...
- UVA - 590Always on the run(递推)
题目:UVA - 590Always on the run(递推) 题目大意:有一个小偷如今在计划着逃跑的路线,可是又想省机票费. 他刚開始在城市1,必须K天都在这N个城市里跑来跑去.最后一天达到城市 ...
- UVA 11077 Find the Permutations 递推置换
Find the Permutations Sorting is one of the most used operations in real ...
- UVA 10943 - How do you add? 递推
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 926【简单dp,递推】
UVa 926 题意:给定N*N的街道图和起始点,有些街道不能走,问从起点到终点有多少种走法. 很基础的dp.递推,但是有两个地方需要注意,在标记当前点某个方向不能走时,也要同时标记对应方向上的对应点 ...
- UVa 825【简单dp,递推】
UVa 825 题意:给定一个网格图(街道图),其中有一些交叉路口点不能走.问从西北角走到东南角最短走法有多少种.(好像没看到给数据范围...) 简单的递推吧,当然也就是最简单的动归了.显然最短路长度 ...
- Uva 11077 Find the Permutations [置换群 DP]
题意: 给定$n$和$k$,问有多少排列交换$k$次能变成升序 $n \le 21$ $uva$貌似挂掉了$vjudge$上一直排队 从某个排列到$1,2,...,n$和从$1,2,...,n$到某个 ...
- UVa 10288 - Coupons(数学期望 + 递推)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- Android - NullPointerException
Android中的空指针,感觉出现率,比普通的java出现的概率多得多,今天我无意中发现的NullPointerException,还是想记录下来. 我们知道, 我们的控件一般定义在layout.xm ...
- Parse和Convert的区别
DateTime.Parse是转换String为DateTime Convert.ToDateTime是转换继承自Object的对象为DateTime的. 你得到一个object对象,你想把它转换为D ...
- RESTful 架构风格概述
http://blog.igevin.info/posts/restful-architecture-in-general/(非常好) http://blog.igevin.info/posts/re ...
- Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction policies
Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction pol ...
- 数据库(学习整理)----1--如何彻底清除系统中Oracle的痕迹(重装Oracle时)
1.关于重装Oracle数据库: 由于以前装过Oracle数据库,但是版本不怎么样,结果过了试用期之后,我就没有破解和再找合适的版本了!直接使用电脑管家卸载了!可想而知,肯定没清除Oracle痕迹啊! ...
- 2D动态光照
对场景内所有点发出射线, 如果射线被某条边阻挡, 则射线停留在阻挡的边上, 如果射线顺利抵达终点, 则对射线偏移-0.001, +0.001角度, 再射出2条射线, 停留在后续的阻挡边上. 把最终的射 ...
- Win32中GDI+应用(五)--GDI与GDI+编程模型的区别
在GDI里面,你要想开始自己的绘图工作,必须先获取一个device context handle,然后把这个handle作为绘图复方法的一个参数,才能完成任务.同时,device context ha ...
- js调用.net后台事件,和后台调用前台等方法以及js调用服务器控件的方法
http://blog.csdn.net/deepwishly/article/details/6670942 ajaxPro.dll基础教程(前台调用后台方法,后台调用前台方法) 1. javaS ...
- demo_03HTML5中的动画效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- js获取时间加多山天和时间戳转换成日期
function huoqu(){ var data = $("#data").val();//获取的时间 var day = $('#day').val();//往后 ...