Codeforces Round #349 (Div. 2) C. Reberland Linguistics 【DP】

/* ***********************************************
Author        :Maltub
Email         :[email protected]
Blog          :htttp://www.xiang578.com
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
//#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
using namespace std;
typedef vector<int> VI;
typedef long long ll;
const ll mod=1000000007;
const int N=2048;
char s[100000+10];
int dp[10000+10][5];
map<string,int>mp;
vector<string>v;
int len;

int get(int st,int l)
{
    string t1,t2,t3;
    if(st+l>len)
        return 0;
    else if(st+l==len)
    {
        for(int i=0; i<l; i++)
            t1+=s[st+i];
        if(mp[t1]==0)
        {
            mp[t1]++;
            v.push_back(t1);
        }
    }
    else
    {
        int f=0,s2=st+l;
        for(int i=0; i<l; i++)
            t1+=s[st+i];
        for(int i=0;i<2;i++)
            t2+=s[s2+i];
        for(int i=0;i<3;i++)
            t3+=s[s2+i];
       if(l==2)
       {
           if(t1!=t2&&dp[s2][2]) f=1;
           if(dp[s2][3]) f=1;
       }
       else if(l==3)
       {
           if(t1!=t3&&dp[s2][3]) f=1;
           if(dp[s2][2]) f=1;
       }
        if(f==0) return 0;
        if(mp[t1]==0)
        {
            mp[t1]++;
            v.push_back(t1);
        }
    }
    return 1;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    memset(s,0,sizeof(s));
    scanf("%s",s);
    v.clear();
    mp.clear();
    memset(dp,0,sizeof(dp));
    len=strlen(s);
    for(int i=len-1; i>=5; i--)
    {
        dp[i][2]=get(i,2);
        dp[i][3]=get(i,3);
    }
    sort(v.begin(),v.end());
    printf("%d\n",v.size());
    for(int i=0; i<v.size(); i++)
    {
        cout<<v[i]<<endl;
    }
    return 0;
}
时间: 2024-11-05 16:08:25

Codeforces Round #349 (Div. 2) C. Reberland Linguistics 【DP】的相关文章

Codeforces Round #349 (Div. 2) C. Reberland Linguistics DP+set

C. Reberland Linguistics First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in d

Codeforces Round #349 (Div. 2) D. World Tour 【spfa+暴力枚举】

/* *********************************************** Author :Maltub Email :[email protected] Blog :htttp://www.xiang578.com ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #inclu

Codeforces Round #540 (Div. 3) C. Palindromic Matrix 【暴力】

任意门:http://codeforces.com/contest/1118/problem/C C. Palindromic Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call some square matrix with integer values in its cells palind

Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】

一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别 对于第三组数据不是很懂,为啥312,132的组合是不行的 后来发现这是一道考察并查集的题目 QAQ 怒贴代码: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostream> 6 #include <algorithm> 7

Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister(DP)

题目链接:Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister 题意: 有n层楼,每层有m个房间,每层的两边是楼梯. 现在有一个人站在左下角,这个人必须将这一层的灯关闭后才能去另外一层. 每移动一次需要1分钟,问关闭所有灯需要多少时间. 题解: 考虑DP[i][j]表示当前已经关闭了第i层全部的灯,j=0时表示在这一层的最左边,j=1时表示在这一层的最右边. 然后推上去就行了.最后讨论一下特殊情况. 1 #include<bits/

Codeforces Round #360 (Div. 2) D 数学推导 E dp

Codeforces Round #360 (Div. 2) A  == B  水,但记一下: 第 n 个长度为偶数的回文数是  n+reverse(n). C    dfs 01染色,水 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i

Codeforces Round #349 (Div. 2)

终于又回到熟悉的Round了 数学 A - Pouring Rain 设个未知数,解方程,还好没有hack点 #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; const double PI = acos (-1.0); int main() { double d, h, v, e; scanf ("%lf%lf%lf%lf", &d, &h, &v, &

Codeforces Round #349 (Div. 2) D. World Tour 暴力最短路

D. World Tour A famous sculptor Cicasso goes to a world tour! Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will enti

Codeforces Round #245 (Div. 1) B. Working out (简单DP)

题目链接:http://codeforces.com/problemset/problem/429/B 给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右: 一个人从(n, 1) ->(1, m),只能向上或者向右.必须有一个相遇点, 相遇点的值不能被取到, 问两个人能得到的最大路径和是多少? dp[i][j]:表示从一个点出发的最大值:先预处理从(1,1) (1,m) (n,1) (n,m)四个点出发的4个dp最大值.然后枚举所有的点,但是这个点不能在边缘,考虑枚举点不够