• 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;
    }
  • 相关阅读:
    [ZT]The 10 best crossplatform applications
    [Today Words] 20090602
    [转] 各种豆浆的做法(搭配美图) 超赞!!不得不看哦~
    .NET Framework Tools
    格式化XML:输出有缩进效果的XML字符串
    The Open Source Definition
    【ZT】新东方10天背5500词汇经典讲座
    《代码大全2》阅读笔记16 Chapter 13 Unusual Data Types
    【ZT】C#语法之fixed 语句
    【MSDN】PDB 文件(C#、J# 和 Visual Basic)
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4296969.html
Copyright © 2020-2023  润新知