随笔-11  评论-0  文章-0  trackbacks-0
 1
 2void cantor(int N,int K)
 3// N! Kth
 4    // cantor extend
 5    int x=K,cant[100],n=2;
 6    memset(cant,0,sizeof(cant));
 7    for( ; x ; n++){
 8        printf("%d*%d! ",x%n,n-1);
 9        cant[n]=x%n;
10        x/=n;
11    }

12    // convert to permutation
13    int p[100];memset(p,0,sizeof(p));
14    for(int i=n-1;i>=1;i--){
15        // cant []
16        int cnt=0;
17        for(int  j=2;j<=n;j++){
18            // p[]
19            if(cnt==cant[i] && !p[j]){
20                p[j]=i;
21                break;
22            }

23            if( p[j]<i)cnt++;
24        }

25    }

26    //out 
27    for(int i=n;i>=2;i--){
28        printf("%d ",p[i]);
29    }

30    while(n<=N){printf("%d ",n++);}
31    printf("\n");
32}

33
posted on 2009-07-20 12:56 iyixiang 阅读(220) 评论(0)  编辑 收藏 引用 所属分类: acm

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理