zoukankan      html  css  js  c++  java
  • UVA 11077 Find the Permutations

    /*
        dp[i][j]表示递推到i时,swap的次数为j时的方案数。
        i要么单独形成1个循环节,这时不增加swap的次数,要么放到前i-1个数某个数的后面,从而插入到某个循环中,这样swap的次数会+1。 
    */
    #include<stdio.h>
    #include<string.h>
    typedef unsigned long long LL;
    int N, K;
    LL dp[25][25];
    void prep()
    {
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for(int i = 1; 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);    
            }
    }
    int main()
    {
        prep();
        while(scanf("%d%d", &N, &K), N)
            printf("%llu\n", dp[N][K]);
        return 0;    
    }
  • 相关阅读:
    SpringBoot整合阿里云OSS
    UVALive
    HDU 5794 A Simple Chess dp+Lucas
    数论
    UVALive
    UVALive
    HDU 5792 World is Exploding 树状数组+枚举
    UVALive
    UVALive
    UVALive
  • 原文地址:https://www.cnblogs.com/staginner/p/2751128.html
Copyright © 2011-2022 走看看