UVA - 11077 Find the Permutations 置换群+斯特林数

我们可以将这个排列写成循环的形式,可知,一个大小为x循环,需要对换x-1次才能对换完成

所以题目的意思就是有多少种排列有n-k个循环,等价于n个数分成n-k个园排列的方案数,这正是第一类斯特林数。。不过要注意,,这题要用ULL。。

#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string.h>
#include<string>
#include<cstring>
#include<vector>
#include<time.h>
#include<stdlib.h>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define fuck(x) cout<<x<<endl;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
const double eps=1e-5;
const int P=1e9+7;
const int MX=1e6+5;
int n,k;
ULL S[33][33];
int main()
{
    S[0][0]=1;
    for(int i=0; i<=21; i++)
        for(int j=0; j<=21; j++)
        {
            if(i==0&&j==0)continue;
            S[i][j]=0;
            if(i-1>=0&&j-1>=0)S[i][j]+=S[i-1][j-1];
            if(i-1>=0)S[i][j]+=(i-1)*S[i-1][j];
        }
    while(cin>>n>>k&&n)
    {
        cout<<S[n][n-k]<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值