UVA 11077 Find the Permutations(置换+dp)

nk
xx1
dp[i][j]ij
dp[i][j]=dp[i1][j]1+dp[i1][j1](i1)
iii1j
ii1i
unsignedlonglong


代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#pragma comment(linker,"/STACK:102400000,102400000")

using namespace std;
#define   MAX           10005
#define   MAXN          1000005
#define   maxnode       205
#define   sigma_size    2
#define   lson          l,m,rt<<1
#define   rson          m+1,r,rt<<1|1
#define   lrt           rt<<1
#define   rrt           rt<<1|1
#define   middle        int m=(r+l)>>1
#define   LL            long long
#define   ull           unsigned long long
#define   mem(x,v)      memset(x,v,sizeof(x))
#define   lowbit(x)     (x&-x)
#define   pii           pair
#define   bits(a)       __builtin_popcount(a)
#define   mk            make_pair
#define   limit         10000

//const int    prime = 999983;
const int    INF   = 0x3f3f3f3f;
const LL     INFF  = 0x3f3f;
//const double pi    = acos(-1.0);
const double inf   = 1e18;
const double eps   = 1e-9;
const LL     mod   = 1e9+7;
const ull    mx    = 133333331;

/*****************************************************/
inline void RI(int &x) {
      char c;
      while((c=getchar())<'0' || c>'9');
      x=c-'0';
      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
 }
/*****************************************************/

ull dp[25][25];
int main(){
    //freopen("in.txt","r",stdin);
    int n,k;
    while(cin>>n>>k&&n){
        mem(dp,0);
        for(int i=1;i<=n;i++) dp[i][0]=1;
        for(int i=2;i<=n;i++){
            for(int j=1;j1][j]+dp[i-1][j-1]*(i-1);
            }
        }
        cout<return 0;
}

你可能感兴趣的:(UVA 11077 Find the Permutations(置换+dp))