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. UVA 11100 The Trip, 2007 水题一枚

    题目链接:UVA - 11100 题意描述:n个旅行箱,形状相同,尺寸不同,尺寸小的可以放在尺寸大的旅行箱里.现在要求露在最外面的旅行箱的数量最少的同时满足一个旅行箱里放的旅行箱的数量最少.求出这样满 ...

  2. DailyMasalaCMS升级记录

    手头上是一个比较老的工程,Jdk1.7 + Tomcat7.0 + Spring 3.x + Hibernate 3.x + Elasticseach 2.x 最近Elasticsearch升级,ja ...

  3. HDFS冗余数据块的自动删除

    HDFS冗余数据块的自动删除 在日常维护hadoop集群的过程中发现这样一种情况: 某个节点由于网络故障或者DataNode进程死亡,被NameNode判定为死亡,HDFS马上自动开始数据块的容错拷贝 ...

  4. 微信小程序 - 对象转换成对象数组

    后端传过来的一个个对象 {1,2,3,4},{1,3,5,},{1,3,5} 我们应该转化为数组对象 [{},{},{},{}]  ,最后通过wx:for遍历到页面 示例图:

  5. java查看工具jinfo-windows

    Generates configuration information. This command is experimental and unsupported. Synopsis jinfo [  ...

  6. linux 系统时间硬件时间同步

    1.设置系统时间:date-s 21/05/2016 date -s 08:21:21 2.系统时间同步到硬件时间: clock --systohc

  7. 总结自己使用shell命令行经常使用到的8个小技巧

    原创blog,转载请注明出处 Shell是命令解释器 [root@localhost ~]# cat /etc/shells 查看本系统共支持哪些shell 1 tab 命令补全 这个差点儿每次都能用 ...

  8. 【Python】读取cvs文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6: invalid start byte

    现在有文件data.csv 文件编码格式为:ANSI data.csv 1|1|1|北京市 2|1|2|天津市 3|1|3|上海市 4|1|4|重庆市 5|1|5|石家庄市 6|2|5|唐山市 7|3 ...

  9. DataTable行处理

    DataTable dt=new DataTable(); 新增行: DataRow addDR= mydatatable.NewRow();addDR["ID"] = " ...

  10. 试验笔记 - 使用7-ZIP压缩来减小APK安装包体积

    7-ZIP版本:9.20 x86 And x64 Windows(2010-11-18) 1. 将APK包解压到文件夹2. 全选所有文件,右键“添加到压缩包”3.“压缩格式”必须“zip”4.“压缩等 ...