Crack

46 篇文章 1 订阅

1410. Crack

Time limit: 0.5 second
Memory limit: 64 MB
Today Arthur has got not the best day of his life. Today is Thursday and in the morning he had to lie under a bulldozer, which was pulling down his house, and his planet is destroyed, and Marvin is a pain in the neck. And now Arthur is standing in front of Vl'hurgs' commander and he has to speak, otherwise in the space-time continuum a tiny crack will appear and so on... May be exactly Arthur will have this crack. For example, in the bones of his skull. So, he is to speak immediately and certainly in Vl'hurgish. There's only one problem: the only thing that Arthur has heard in Vl'hurgish is the demand to surrender that was proclaimed a second ago. The Hitchhiker's Guide to the Galaxy can only prompt to Arthur that the Vl'hurgish language is very complicated. There are millions of rules and some of them are very amusing. For instance, no Vl'hurgish word can be pronounced for more seconds than the number of letters it consists of. They don't like mumblers. It's known as well that Vl'hurgs don't like when replying to some remark you use any of the two-word combinations that were contained in the original remark. In this case they may think that you parody them and parodists are out of favor among Vl'hurgs. But Arthur is to say something! He has decided to repeat the phrase of Vl'hurgs' commander having thrown out just several words and not changing their order. What else can he do? Just gain time pronouncing each word as long as it is possible.
But how much time can he gain this way?

Input

The input contains a phrase of Vl'hurgs' commander. The words consist just of lower-case and capital Latin letters. Any other symbols are word separators. The phrase doesn't contain two equal words (the case of letters should be ignored). The length of any Vl'hurgish word is not greater than 100. The amount of words in one phrase doesn't exceed 10000. Total input size doesn't exceed 512 KB.

Output

Output a single number: the maximal time in seconds that Arthur may speak. Of course, Arthur doesn't want to seem a mumbler or parodist.

Sample

input output
You have come a long way
11

Hint

In the sample Arthur should say "You come long".
/**
给一个字符串有单词和标点以及空格组成。在该串中寻找字串。使得该子串有原串种的若干单词组成,
且子串中两个相邻单词在原串中不能相邻。原串中的单词各不相同。求该字串最长多少。

实际上,对于第j个单词,我们去前j-2个中的最大dp,再加上第j个单词的长度,便是第j个单词位于子串末时的answer。
最后,再枚举一下所有的j,取dp最大值。

题目的坑在于输入上~~~
**/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>

using namespace std;

int n;
int len[10010];
int  dp[10010];
int ans;
string s;

void DP()
{
    dp[1]=len[1];
    dp[2]=len[2];
    dp[3]=len[1]+len[3];

    int maxdp=dp[1]<dp[2]?2:1;//本打算练一下单调队列,发现用不上= =!

    for(int i=4; i<=n; i++)
    {
        dp[i]=dp[maxdp]+len[i];

        if(dp[i-1]>dp[maxdp])
            maxdp=i-1;
    }
    for(int i=1; i<=n; i++)
        ans=max(dp[i],ans);
}

int check(char a)
{
    if ((a>='a'&&a<='z')||(a>='A'&&a<='Z'))
        return 1;
    return 0;
}

int main()
{
    int sum = 0;
    while(getline(cin,s))//如此读,因为会出现以回车作为间隔符的情况
    {
        s.push_back(' ');
        for (int i=0; i<s.length(); i++)
        {
            if (!check(s[i]))//只记录字母数
            {
                if (sum)
                {
                    len[++n]=sum;
                    sum = 0;
                }
                continue;
            }
            sum++;
        }
        s.clear();
    }
    DP();
    printf("%d\n",ans);
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值