HDoj 2062 Subset sequence

参考了 https://blog.csdn.net/qq_33266889/article/details/53468509

暂时没搞懂,以后再研究:

#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main()
{
    long long g[21];
    int s[21];
    g[0]=1;
    for(int i=1;i<=20;i++)
        g[i]=g[i-1]*(i-1)+1;
    int n;
    long long m;
    while(scanf("%d%lld",&n,&m)!=EOF)
    {
        for(int i=0;i<=20;i++)
            s[i]=i;
        while(n>0&&m>0)
        {
            int t=m/g[n]+(m%g[n]>0? 1:0);
            if(t>0)
            {
                printf("%d",s[t]);
                for(int i=t;i<=n;i++)
                    s[i]=s[i+1];
                m=m-(t-1)*g[n]-1;
                if(m==0)
                    printf("\n");
                else
                    printf(" ");
            }
            n--;
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/wzmm/p/12747154.html