UVa 11077 Find the Permutations / 置换
来源:互联网 发布:b超单数据怎么看 编辑:程序博客网 时间:2024/05/18 17:58
把一个排列p变成1,2,...,n可以反过来看成1,2,...,n到p
把p分解乘循环 如果一个循环有n个元素 需要n-1次交换
dp[i][j] = dp[i-1][j] + dp[i-1][j-1] * (i-1); 代表i个元素 交换j次变成1,2,...,n,的种数
对于元素i 他可以自己成为一个循环那么交换次数不变 种数+1 就是 dp[i-1][j]
加入前面任意循环的任一个位置 有i-1中 就是dp[i-1][j-1]*(i-1);
#include <cstdio>#include <cstring>const int maxn = 30;unsigned long long dp[maxn][maxn];int main(){memset(dp, 0, sizeof(dp));dp[1][0] = 1;for(int i = 2; i <= 21; i++){for(int j = 0; j < i; j++){dp[i][j] = dp[i-1][j];if(j > 0)dp[i][j] += dp[i-1][j-1] * (i-1);}}int n, k;while(scanf("%d %d", &n, &k) == 2 && n)printf("%llu\n", dp[n][k]);return 0;}
0 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(排列统计)
- 内核对象--可等待计时器WaitableTimer(一)
- UVA 11090 - Going in Cycle!! SPFA
- POJ 3013 Big Christmas Tree(Dijkstra,裸)
- Trademiner, Stocks, Futures & Forex!
- 解决/usr/bin/dpkg returned an error code (1)
- UVa 11077 Find the Permutations / 置换
- 类和对象_定义类2
- C++ windowns多线程
- Ubuntu_FTP命令全集
- nyoj-3-多边形重心问题
- poj 1742 Coins(多重背包)
- 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'users' 中的标识列插入显式值
- 1001
- WM_DESTROY ,WM_CLOSE ,WM_QUIT 的区别