UVA 11077 - Find the Permutations

option=com_onlinejudge&Itemid=8&page=show_problem&category=485&problem=2018&mosmsg=Submission+received+with+ID+13900478" target="_blank" style="">题目链接

题意:给定n,k求出有多少个包括元素[1-n]的序列,交换k次能得到一个[1,2,3...n]的序列

思路:递推dp[i][j]表示i个元素须要j次。那么在新加一个元素的时候。添在最后面次数不变。其余位置都是次数+1,这是能够证明的。原序列中有几个循环,须要的次数就是全部循环长度-1的和,那么对于新加一个元素,加在最后就和自己形成一个循环。次数不变,其余位置都会增加其它循环中,次数+1。因此递推式为dp(i,j)=dp(i−1,j−1)∗(i−1)+dp(i−1,j)

代码:

#include <stdio.h>
#include <string.h> const int N = 22;
int n, k;
unsigned long long dp[N][N]; int main() {
dp[1][0] = 1;
for (unsigned long long i = 2; i <= 21; i++) {
for (int j = 0; j < i; j++) {
dp[i][j] = dp[i - 1][j];
if (j) dp[i][j] += dp[i - 1][j - 1] * (i - 1);
}
}
while (~scanf("%d%d", &n, &k) && n || k) {
printf("%llu\n", dp[n][k]);
}
return 0;
}

UVA 11077 - Find the Permutations(递推)的更多相关文章

  1. UVA 11077 Find the Permutations 递推置换

                               Find the Permutations Sorting is one of the most used operations in real ...

  2. UVa 11077 Find the Permutations(置换+递推)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35431 [思路] 置换+递推 将一个排列看作一个置换,分解为k个循 ...

  3. UVA 557 Burger 排列组合递推

    When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was held at t ...

  4. UVA 10559 Blocks(区间DP&&递推)

    题目大意:给你玩一个一维版的消灭星星,得分是当前消去的区间的长度的平方,求最大得分. 现在分析一下题目 因为得分是长度的平方,不能直接累加,所以在计算得分时需要考虑前一个状态所消去的长度,仅用dp[l ...

  5. UVa 1638 Pole Arrangement【递推】

    题意:给出n根高度为1,2,3,---n的杆子,从左边能看到l根,右边能够看到r根,问有多少种可能 看的紫书的思路 先假设已经安排好了高度为2---i的杆子, 那么高度为1的杆子的放置方法有三种情况 ...

  6. UVA 11464 偶数矩阵(递推 | 进制)

    题目链接:https://vjudge.net/problem/UVA-11464 一道比较好的题目. 思路如下: 如果我们枚举每一个数字“变”还是“不变”,那么需要枚举$2^{255}$种情况,很显 ...

  7. Uva 11300 Spreading the Wealth(递推,中位数)

    Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...

  8. Uva 11077 Find the Permutations [置换群 DP]

    题意: 给定$n$和$k$,问有多少排列交换$k$次能变成升序 $n \le 21$ $uva$貌似挂掉了$vjudge$上一直排队 从某个排列到$1,2,...,n$和从$1,2,...,n$到某个 ...

  9. UVa 580 - Critical Mass(递推)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. Java 在Word创建表格

    表格作为一种可视化交流模式及组织整理数据的手段,在各种场合及文档中应用广泛.常见的表格可包含文字.图片等元素,我们操作表格时可以插入图片.写入文字及格式化表格样式等.下面,将通过Java编程在Word ...

  2. ios内存管理笔记(三)

    我们在进行iOS开发时,经常会在类的声明部分看见类似于@synthesize window=_window; 的语句,那么,这个window是什么,_ window又是什么,两个东西分别怎么用,这是一 ...

  3. Using Find_Alert and Show_Alert in Oracle Forms

    Show_alert is used to display model window messages in Oracle Forms and Find_alert searches the list ...

  4. Scut游戏服务器引擎之Unity3d接入

    Scut提供Unity3d Sdk包,方便开发人员快速与Scut游戏服务器对接: 先看Unity3d示例如下: 启动Unity3d项目 打开Scutc.svn\SDK\Unity3d\Assets目录 ...

  5. memcache 开机启动

    一. 通常:启动Memcache的服务器端的命令为:# /usr/local/bin/memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 - ...

  6. JavaScript中给二维数组动态添加元素的质朴方法

    var myData = new Array(); for(var i=0;i<tableDatas.length;i++){ var arr=tableDatas[i]; ...... /// ...

  7. quartz 应用到 spring定时任务 执行两次

    https://my.oschina.net/superkangning/blog/467487

  8. Vue2.0 引用 exif.js 实现调用摄像头进行拍照功能以及图片上传功能

    vue组件代码 <template> <div> <div style="padding:20px;"> <div class=" ...

  9. fiddler不能监听 localhost和 127.0.0.1的问题 .

    localhost/127.0.0.1的请求不会通过任何代理发送,fiddler也就无法截获. 解决方案 用 http://localhost. (locahost紧跟一个点号) 用 http://1 ...

  10. SharePoint 的PowerShell命令之获取所有网站模版

    Get-SPWebTemplate | select Name, Title