uva 11077 - Find the Permutations(置换+dp)
来源:互联网 发布:手机笑声音效软件 编辑:程序博客网 时间:2024/05/18 20:35
题意:对于1~n的排列,至少交换k次才能变成1,2,3,...,n的有多少个
思路:假设每一个排列是一个置换,这个置换里有x个循环,那么这个置换想变成1,2,3,...,n至少交换n-x次,所以题意也就是有多少个排列,里面的循环<=n-k个
这个可以有dp来做,dp[i][j]表示至少交换j次,变成1,2,...,i
dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(i-1)
dp[i-1][j]:因为这个i可以单独为一个循环
dp[i-1][j-1]*(i-1):这个i也可以加入前面的任意一个循环的任何位置
#include<bits/stdc++.h>using namespace std;typedef unsigned long long LL;const int maxn=50;LL dp[maxn][maxn];int N,K;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); } while(scanf("%d%d",&N,&K)!=EOF,N+K) cout<<dp[N][K]<<endl; return 0;}
1 0
- UVA 11077 Find the Permutations(置换+dp)
- uva 11077 - Find the Permutations(置换+dp)
- UVA 11077 Find the Permutations(置换+dp)
- UVA Find the Permutations 11077 (DP&置换群)
- UVa 11077 Find the Permutations / 置换
- uva 11077 - Find the Permutations(置换)
- UVA - 11077 Find the Permutations (置换)
- UVA 11077 Find the Permutations(置换)
- UVA 11077 Find the Permutations 置换+递推
- uva 11077 Find the Permutations 置换+递推
- UVA 11077 Find the Permutations DP
- UVa11077-Find the Permutations(dp+置换)
- Find the Permutations [Uva 11077]
- UVA 11077 - Find the Permutations(递推)
- Find the Permutations UVA11077
- uva11077 Find the Permutations
- uva11077 Find the Permutations
- UVA11077 Find the Permutations(排列统计)
- TIBCO Enterprise Message Service功能介绍
- 四种内存管理类及用法
- android导入eclipse项目后,gradle版本引起的问题
- hibernate异常:解决Hibernate的Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL):
- 百度地图getAddrStr()方法返回为空的问题
- uva 11077 - Find the Permutations(置换+dp)
- 美元兑人民币汇率对黄金价格的预测
- 求循环素数
- Block的循环引用问题
- Android导航菜单横向左右滑动并和上方的控件实现联动
- 没有iptables文件的情况,防火墙开启3306端口
- Python heapq模块
- Linux编写Shell脚本自动同步svn并发布maven项目-SSH连接远程服务
- 面向对象与面向过程区别