zoukankan      html  css  js  c++  java
  • F. Rhyme scheme

    题: https://nanti.jisuanke.com/t/41414

    #include<bits/stdc++.h>
    using namespace std;
    typedef __int128 ll;
    const int M=30;
    const int mod=1e9+7;
    ll dp[M][M];
    int a[M];
    int n;
    
    inline ll read() {
        ll x = 0, f = 1;
        char c = getchar();
        for (; !isdigit(c);c = getchar()) if (c == '-') f = -1;
        for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
        return x * f;
    }
    ll dfs1(int pos,int up){
        if(pos==n+1)
            return 1;
        if(~dp[pos][up])
            return dp[pos][up];
        ll sum=0;
        for(int i=0;i<=up;i++){
            sum+=dfs1(pos+1,max(up,i+1));
        }
        dp[pos][up]=sum;
        return sum;
    }
    void dfs2(int pos,int up,ll r){
        if(pos==n+1){
            for(int i=1;i<=n;i++)
                putchar(a[i]+'A');
            puts("");
            return ;
        }
        for(int i=0;i<=up;i++){
            int nowup=max(i+1,up);
            if(r<=dp[pos+1][nowup]){
                a[pos]=i;
                dfs2(pos+1,nowup,r);
                break;
            }
            else
                r-=dp[pos+1][nowup];
        }
    }
    int main(){
        int t;
        scanf("%d",&t);
        for(int ca=1;ca<=t;ca++){
            scanf("%d",&n);
            ll k=read();
            for(int i=0;i<M;i++)
                for(int j=0;j<M;j++)
                    dp[i][j]=-1;
            for(int i=0;i<M;i++)
                dp[n+1][i]=1;
        //    cout<<"!!"<<endl;
            dfs1(1,0);
            printf("Case #%d: ",ca);
            dfs2(1,0,k);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    PHP 对Memcache的使用实例
    PHP Memcache 扩展安装
    Effective STL 读书笔记
    windows下安装和使用scrapy
    使用insert ignore来避免向数据库重复插入数据
    2017年末
    归并排序
    二叉树的中序遍历
    正则表达式
    tinymq学习小结
  • 原文地址:https://www.cnblogs.com/starve/p/11525167.html
Copyright © 2011-2022 走看看