zoukankan      html  css  js  c++  java
  • USACO Longest Prefix 【水】

    用Dp的思想解决了这道题目,也就是所谓的暴力= = 

    题意:给出一个集合,一个字符串,找出这个字符串的最长前缀,使得前缀可以划分为这个集合中的元素(集合中的元素可以不全部使用)。

    还不会Trie 树QAQ

    Source Code:

    /*
    ID: wushuai2
    PROG: prefix
    LANG: C++
    */
    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #define Max(a,b) (((a) > (b)) ? (a) : (b))
    #define Min(a,b) (((a) < (b)) ? (a) : (b))
    #define Abs(x) (((x) > 0) ? (x) : (-(x)))
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define RV(num) ((num) > 0 ? 0 : 1)
    
    using namespace std;
    
    typedef long long           ll      ;
    typedef unsigned long long  ull     ;
    typedef unsigned int        uint    ;
    typedef unsigned char       uchar   ;
    
    template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
    template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;}
    
    const double eps = 1e-7      ;
    const int M = 660000         ;
    const ll P = 10000000097ll   ;
    const int INF = 0x3f3f3f3f   ;
    const int MAX_N = 20         ;
    const int MAXSIZE = 101000000;
    
    string str[220];
    char a[2200000];
    bool vis[220000];
    int str_num, len, len_a;
    
    int main() {
        ofstream fout ("prefix.out");
        ifstream fin ("prefix.in");
        int i, j, k, l, m, n, t, s, c, w, q, num;
        for(;;){
            fin >> str[++str_num];
            if(str[str_num].compare(".") == 0)  break;
        }
        while(fin >> a[len_a++])
        vis[0] = true;
        for(i = 0; i < len_a; ++i){
            if(!vis[i]) continue;
            for(j = 1; j < str_num; ++j){
                int length_str = str[j].length();
                if(length_str + i >= len_a)   continue;
                for(k = 0; k < length_str; ++k){
                    if(a[i + k] != str[j][k])   break;
                }
                if(k == length_str){
                    checkmax(len, length_str + i);
                    vis[length_str + i] = true;
                }
            }
        }
        fout << len << endl;
    
    
        fin.close();
        fout.close();
        return 0;
    }
  • 相关阅读:
    『在线工具』 基于 xsser.me 源码 + BootStrap 前端 的 XSS 平台
    『Python』Python 调用 ZoomEye API 批量获取目标网站IP
    『Python』 多线程 共享变量的实现
    『Python』 多线程 端口扫描器
    打印机PCL漏洞原理分析
    『GitHub』Git常用命令记录
    『Python』爬行搜索引擎结果获得指定主机二级域名及IP信息
    iOS使用Runtime给分类动态绑定属性
    Swift介绍(基于Swift4版本)
    iOS中的block模板
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4296969.html
Copyright © 2011-2022 走看看