uva 11077 - Find the Permutations(置换)
来源:互联网 发布:淘宝助理一键适配 编辑:程序博客网 时间:2024/05/18 20:05
题目链接:uva 11077 - Find the Permutations
题目大意:给定一个1~n的排序,可以通过一系列的交换变成1,2,…,n, 给定n和k,统计有多少个排列至少需要交换k次才能变成有序的序列。
解题思路:给定一个序列P,可以将该序列看做是一个置换,从有序序列,开始,需要多少次回到有序序列。将P的循环分解,循环长度为1的需要0次,长度为2的需要1次,循环长度为n的需要n-1次,如果P的长度为N,有x个不相干的循环,那么总的需要的交换即为N-x。
所以有状态f(i,j),即为长度i,j个循环的寻列总数,f(i,j)=f(i−1,j−1)∗(i−1)+f(i−1,j)
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef unsigned long long ll;const int maxn = 21;ll f[maxn+5][maxn+5];int main () { memset(f, 0, sizeof(f)); f[1][0] = 1; for (int i = 2; i <= maxn; i++) { for (int j = 0; j < i; j++) { f[i][j] = f[i-1][j]; if (j) f[i][j] += f[i-1][j-1] * (i-1); } } int n, k; while (scanf("%d%d", &n, &k) == 2 && n + k) { printf("%llu\n", f[n][k]); } return 0;}
1 0
- UVa 11077 Find the Permutations / 置换
- UVA 11077 Find the Permutations(置换+dp)
- uva 11077 - Find the Permutations(置换)
- UVA - 11077 Find the Permutations (置换)
- UVA 11077 Find the Permutations(置换)
- uva 11077 - Find the Permutations(置换+dp)
- UVA 11077 Find the Permutations(置换+dp)
- UVA 11077 Find the Permutations 置换+递推
- UVA Find the Permutations 11077 (DP&置换群)
- uva 11077 Find the Permutations 置换+递推
- Find the Permutations [Uva 11077]
- UVA 11077 - Find the Permutations(递推)
- UVA 11077 Find the Permutations DP
- UVa11077-Find the Permutations(dp+置换)
- Find the Permutations UVA11077
- uva11077 Find the Permutations
- uva11077 Find the Permutations
- UVA11077 Find the Permutations(排列统计)
- 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以
- oracle_11数据库安装使用
- linux C复习:程序中加载并调用共享库
- HashTable入门注意小点
- C++ 虚函数表解析
- uva 11077 - Find the Permutations(置换)
- 用C#操作Mongodb(c#mongodb驱动)
- live555源码分析----SETUP命令处理流程
- python静态成员测试类StaticVarTest
- shell 参数
- 自动创建并连接VPN
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- 被JAVA架构师面试后的经验总结
- Netty系列之Netty高性能之道