UVA 11077 - Find the Permutations(递推)
来源:互联网 发布:疯狂的美工手机端 编辑:程序博客网 时间:2024/05/17 14:17
UVA 11077 - Find the Permutations
题目链接
题意:给定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;}
1 0
- UVA 11077 - Find the Permutations(递推)
- UVA 11077 Find the Permutations 置换+递推
- uva 11077 Find the Permutations 置换+递推
- Find the Permutations [Uva 11077]
- 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 DP
- UVA 11077 Find the Permutations(置换)
- uva 11077 - Find the Permutations(置换+dp)
- UVA 11077 Find the Permutations(置换+dp)
- UVA Find the Permutations 11077 (DP&置换群)
- Find the Permutations UVA11077
- uva11077 Find the Permutations
- uva11077 Find the Permutations
- UVa11077-Find the Permutations(dp+置换)
- UVA11077 Find the Permutations(排列统计)
- Python使用设计模式的学习与思考
- SVN中"<<<<<<< .mine“的问题
- hadoop编程小技巧(4)---全局key排序类TotalOrderPartitioner
- Win32消息处理API---GetMessage
- 60个常用linux 的命令
- UVA 11077 - Find the Permutations(递推)
- CSDN开源夏令营 百度数据可视化实践 ECharts(2)
- ruby on rails出现的问题ActiveModel::ForbiddenAttributesError
- 字符串
- 【Unity3D】【NGUI】如何动态给EventDelegate添加参数
- C# - CSV file reader
- OCP exam notes
- 数据挖掘笔记-分类-支持向量机SVM-1
- webApp前端开发技巧总结