10分求调,有调必关
查看原帖
10分求调,有调必关
1643406
shenliyan楼主2025/7/24 22:55
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int MOD=10007;
bool isort(int i,int j,const vector<string>&g){
    if(i>0&&g[i-1][j]!='.'&&g[i][j]!='.'&&g[i-1][j]>g[i][j])
        return false;
    if(j>0&&g[i][j-1]!='.'&&g[i][j]!='.'&&g[i][j-1]>g[i][j])
        return false;
    return true;
}
int main(){
    int T;cin>>T;
    for(int t=1;t<=T;t++){
        int R,C;cin>>R>>C;
        vector<string>g(R);
        for(int i=0;i<R;i++)cin>>g[i];
        bool vld=true;
        for(int i=0;i<R;i++){
            for(int j=0;j<C;j++){
                if(g[i][j]!='.'&&!isort(i,j,g)){
                    vld=false;
                    break;
                }
            }
            if(!vld)break;
        }
        if(!vld){
            cout<<"Case #"<<t<<": 0"<<endl;
            continue;
        }
        vector<vector<vector<int>>>sts;
        sts.resize(R);
        for(int i=0;i<R;i++){
            vector<vector<int>>vld_sts;
            vector<int>cur(C,0);
            vector<int>str(C,0);
            vector<int>end(C,25);
            for(int j=0;j<C;j++){
                if(g[i][j]!='.'){
                    str[j]=g[i][j]-'a';
                    end[j]=g[i][j]-'a';
                }
            }
            for(int c0=str[0];c0<=end[0];c0++){
                cur[0]=c0;
                if(C<2){
                    vld_sts.push_back(cur);
                }else{
                    for(int c1=max(c0,str[1]);c1<=end[1];c1++){
                        cur[1]=c1;
                        if(C<3){
                            vld_sts.push_back(cur);
                        }else{
                            for(int c2=max(c1,str[2]);c2<=end[2];c2++){
                                cur[2]=c2;
                                if(C<4){
                                    vld_sts.push_back(cur);
                                }else{
                                    for(int c3=max(c2,str[3]);c3<=end[3];c3++){
                                        cur[3]=c3;
                                        if(C<5){
                                            vld_sts.push_back(cur);
                                        }else{
                                            for(int c4=max(c3,str[4]);c4<=end[4];c4++){
                                                cur[4]=c4;
                                                if(C<6){
                                                    vld_sts.push_back(cur);
                                                }else{
                                                    for(int c5=max(c4,str[5]);c5<=end[5];c5++){
                                                        cur[5]=c5;
                                                        if(C<7){
                                                            vld_sts.push_back(cur);
                                                        }else{
                                                            for(int c6=max(c5,str[6]);c6<=end[6];c6++){
                                                                cur[6]=c6;
                                                                if(C<8){
                                                                    vld_sts.push_back(cur);
                                                                }else{
                                                                    for(int c7=max(c6,str[7]);c7<=end[7];c7++){
                                                                        cur[7]=c7;
                                                                        if(C<9){
                                                                            vld_sts.push_back(cur);
                                                                        }else{
                                                                            for(int c8=max(c7,str[8]);c8<=end[8];c8++){
                                                                                cur[8]=c8;
                                                                                if(C<10){
                                                                                    vld_sts.push_back(cur);
                                                                                }else{
                                                                                    for(int c9=max(c8,str[9]);c9<=end[9];c9++){
                                                                                        cur[9]=c9;
                                                                                        vld_sts.push_back(cur);
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            sts[i]=vld_sts;
        }
        vector<int>cur(R?sts[0].size():0,0);
        for(int idx=0;idx<(R?sts[0].size():0);idx++){
            bool vld_st=true;
            for(int j=0;j<C;j++){
                if(g[0][j]!='.'&&sts[0][idx][j]!=g[0][j]-'a'){
                    vld_st=false;
                    break;
                }
            }
            if(vld_st)cur[idx]=1;
        }
        for(int i=1;i<R;i++){
            vector<int>nxt(sts[i].size(),0);
            for(int pdx=0;pdx<cur.size();pdx++){
                if(cur[pdx]==0)continue;
                for(int cdx=0;cdx<sts[i].size();cdx++){
                    bool vldt=true;
                    for(int j=0;j<C;j++){
                        if(sts[i-1][pdx][j]>sts[i][cdx][j]){
                            vldt=false;
                            break;
                        }
                    }
                    if(vldt)nxt[cdx]=(nxt[cdx]+cur[pdx])%MOD;
                }
            }
            cur=nxt;
        }
        int ans=0;
        for(int idx=0;idx<cur.size();idx++)ans=(ans+cur[idx])%MOD;
        cout<<"Case #"<<t<<": "<<ans<<endl;
    }
    return 0;
}
2025/7/24 22:55
加载中...