hdoj 5510 Bazinga

题目链接:Bazinga

题目大意:给你一些字符串,问你从上到下最大的条件字符串,这个字符串需要满足在它上面的字符串不能全部都是它的子串,问最大的标记是多少

题目思路:我们可以考虑这样一个问题,如果前面的字符串全部都是这个这个字符串的子串的话,那么我们是不是只考虑这样一个字符串而不需要考虑前面的字符串,如果不是的话我们就可以标记一下记录最大值,然后这样用vector扫一下,剪下枝,扫下去就好了,时间卡的不紧,所以可以过

#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int maxn = 2e3+10;

int T,n;
string str;
int main(){
    ios::sync_with_stdio(false);
    cin>>T;
    for(int Case = 1;Case <= T;Case++){
        int maxxid=-1;
        vector<string>V;
        cin>>n;
        cin>>str;
        V.push_back(str);
        for(int i=1; i<n; i++){
            cin>>str;
            bool flag=true;
            for(int j=0; j<V.size(); j++){
                if(str.find(V[j])==str.npos){
                    flag=false;
                    break;
                }
            }
            if(flag==true)
                V.clear();
            else maxxid=i+1;
            V.push_back(str);
        }
        cout<<"Case #"<<Case<<": "<<maxxid<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值