The Preliminary Contest for ICPC Asia Shanghai 2019 F. Rhyme scheme(dp)

 

 

 

 题意:给你一个n和k 要你找到长度为n 字典序第k小的字符串 定义一个字符串合法:第i的字符的范围只能是前i-1个字符中的最大值+1

思路:我们dp[n][i][j]表示长度为n 在第i位 最大值为j的序列有多少个 随后我们可以直接模仿找第k大一样找到第k个字符串

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 1e6+7;
typedef long long ll;
typedef __int128 bll;
const ll mod = 998244353;
using namespace std;
inline __int128 read() {
     __int128 x=0,f=1;
     char ch=getchar();
     while(ch<'0'||ch>'9') {
         if(ch=='-')
             f=-1;
         ch=getchar();
     }
     while(ch>='0'&&ch<='9') {
         x=x*10+ch-'0';
         ch=getchar();
     }
     return x*f;
}
inline void print(__int128 x)
{    
   if(x<0){putchar('-');x=-x;}
   if(x>9) print(x/10);
   putchar(x%10+'0');
}
bll dp[30][30][30];
char v[30];
bll dfs(int len,int now,int mx){
    if(now==len){
        dp[len][now][mx]=1;
        return dp[len][now][mx];
    }
    if(dp[len][now][mx]!=-1) return dp[len][now][mx];
    bll ans=0;
    for(int i=1;i<=min(mx+1,26);i++){
        if(i<=mx){
            ans+=dfs(len,now+1,mx);
        }else{
            ans+=dfs(len,now+1,i);
        }
    }
    dp[len][now][mx]=ans;
    return ans;
}
int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0); cout.tie(0);
    int t; scanf("%d",&t);
    for(int i=0;i<30;i++)
        for(int j=0;j<30;j++)
            for(int k=0;k<30;k++)
                dp[i][j][k]=-1;
    for(int i=1;i<=26;i++)
        dfs(i,1,1);
    int w=0;
//    print(dp[3][1][1]);
    while(t--){
        int n; scanf("%d",&n);
        bll k; k=read();
        int mx=1;
        printf("Case #%d: ",++w);
        for(int i=1;i<=n;i++){
            v[i]='A'; 
            for(int j=1;j<=mx+1;j++){
                //cout<<k<<" "<<dp[n][i][j]<<endl;
                int p=max(mx,j);
                if(dp[n][i][p]>=k){
                //    mx=max(mx,j);
                    v[i]=char(j+'A'-1);
                    //putchar('A' + j - 1);
                    mx=max(mx,p);
                //    cout<<j<<endl;
                    break;
                }else{
                    k-=dp[n][i][p];
                }
            }
        }
        for(int i=1;i<=n;i++)
            printf("%c",v[i]);
        puts("");
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/wmj6/p/11564257.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I'd be happy to give you some ideas for organizing a speech contest. Here are some suggestions: 1. Determine the theme and rules: Decide on the theme of the contest and the rules for participants. Will it be an open topic, or will there be a specific theme? What is the maximum length of the speech? Will there be any specific guidelines for language or content? 2. Decide on the judging criteria: Determine how the speeches will be evaluated. Will judges be looking for content, delivery, or both? Will there be a score sheet or rubric that judges will use to score the speeches? 3. Recruit judges: Find people who are qualified to judge the speeches. Ideally, they should have experience in public speaking or have a background in the theme of the contest. 4. Promote the contest: Advertise the contest to potential participants, such as students, professionals, or members of a specific community. Use social media, flyers, and other methods to get the word out. 5. Registration and selection: Set a deadline for registration and selection of participants. Consider having a preliminary round to narrow down the field before the final competition. 6. Prepare the venue: Ensure that the venue is suitable for the contest. Make sure that there is adequate seating, sound equipment, and lighting for the speakers. 7. Hold the contest: Set a date and time for the contest, and make sure that all participants and judges are aware of the schedule. Encourage audience participation and provide refreshments. 8. Award ceremony: After the contest, hold an award ceremony to recognize the winners and participants. Provide certificates or other prizes to the top performers. I hope these ideas help you in organizing a successful speech contest!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值