BZOJ2295: 【POJ Challenge】我爱你啊

2295: 【POJ Challenge】我爱你啊

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 126  Solved: 90
[Submit][Status]

Description

ftiasch是个十分受女生欢迎的同学,所以她总是收到许多情书。虽然她十分有魅力,然而她却是个低调的人。因此她从来不会告诉别人她到底收到了多少情书。

ftiasch的好朋友1tthinking想知道她到底收到了多少情书。1tthinking知道,ftiasch每次收到一封情书,就会在日记
最后写下一个包含"luvletter"子序列的串。比如现在ftiasch的日记是alduddvdletterflusvletetedr,那么
ftiasch可能受到了0、1、2封情书。现在给出一些ftiasch的日记,问对于每篇日记,ftiasch最多可能受到多少的情书。

某个序列的子序列是从最初序列通过去除某些元素但不破坏馀下元素的相对位置而形成的新序列。參考wikipedia

Input

第1行,一个整数 T (0 ≤ T ≤ 100), 日记的数量。

第2到 T + 1行,ftiasch的日记 (只包含‘a‘-‘z‘ 和空格, 长度小于100001)

Output

第1到T行,一个整数, 最大可能的情书数量。

Sample Input

5
t
llllluvletterrr
luvletterlauavalaeatataearaluvletter
is wzk a famous boy yes buz he always receives a lot of luv letters
my heart beats her waves at the shore of the world and writes upon it her signature in tears with the words i love thee

Sample Output

0
1
3
1
0

HINT

Source

题解:
给题面点个赞!
刚开始看成DP了,后来发现直接模拟匹配就可以了。。。
代码:

 1 #include<cstdio>
 2
 3 #include<cstdlib>
 4
 5 #include<cmath>
 6
 7 #include<cstring>
 8
 9 #include<algorithm>
10
11 #include<iostream>
12
13 #include<vector>
14
15 #include<map>
16
17 #include<set>
18
19 #include<queue>
20
21 #include<string>
22
23 #define inf 1000000000
24
25 #define maxn 100000
26
27 #define maxm 500+100
28
29 #define eps 1e-10
30
31 #define ll long long
32
33 #define pa pair<int,int>
34
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42
43 #define mod 1000000007
44
45 using namespace std;
46
47 inline int read()
48
49 {
50
51     int x=0,f=1;char ch=getchar();
52
53     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
54
55     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
56
57     return x*f;
58
59 }
60 char s[10]="luvletter";
61 int f[100];
62
63 int main()
64
65 {
66
67     freopen("input.txt","r",stdin);
68
69     freopen("output.txt","w",stdout);
70
71     int cs=read();
72     while(cs--)
73     {
74        char ch=‘ ‘;int now=0,ans=0;
75        while((ch<=‘z‘&&ch>=‘a‘)||(ch==‘ ‘))
76        {
77            ch=getchar();
78            if(ch==s[now]){now++;if(now==9)now=0,ans++;}
79        }
80        printf("%d\n",ans);
81     }
82
83     return 0;
84
85 } 

时间: 2024-08-08 01:12:45

BZOJ2295: 【POJ Challenge】我爱你啊的相关文章

2292: 【POJ Challenge 】永远挑战

2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 230[Submit][Status][Discuss] Description lqp18_31和1tthinking经常出题来虐ftiasch.有一天, lqp18_31搞了一个有向图,每条边的长度都是1. 他想让ftiasch求出点1到点 N 的最短路."水题啊.", ftiasch这么说道. 所以1tth

BZOJ2288: 【POJ Challenge】生日礼物

2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 771  Solved: 238[Submit][Status][Discuss] Description ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超过 M 个连续的部分作为自己的生日礼物. 自然地,ftiasch想要知道选择元素之和的最大值.你能帮助她吗? Input

bzoj2287【POJ Challenge】消失之物(dp+补集转化,好题)

2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 657  Solved: 382[Submit][Status][Discuss] Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. “要使用剩下的 N - 1 物品装满容积为 x 的背包,有几种方法呢?” -- 这是经典的问题了.她把答案记为 Count(

【BZOJ 2288】 2288: 【POJ Challenge】生日礼物 (贪心+优先队列+双向链表)

2288: [POJ Challenge]生日礼物 Description ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超过 M 个连续的部分作为自己的生日礼物. 自然地,ftiasch想要知道选择元素之和的最大值.你能帮助她吗? Input 第1行,两个整数 N (1 ≤ N ≤ 105) 和 M (0 ≤ M ≤ 105), 序列的长度和可以选择的部分. 第2行, N 个整数 A1, A2, ..., AN (0

BZOJ2292: 【POJ Challenge 】永远挑战

2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][Status] Description lqp18_31和1tthinking经常出题来虐ftiasch.有一天, lqp18_31搞了一个有向图,每条边的长度都是1. 他想让ftiasch求出点1到点 N 的最短路."水题啊.", ftiasch这么说道. 所以1tthinking把某些

BZOJ2287: 【POJ Challenge】消失之物

2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][Status] Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. “要使用剩下的 N - 1 物品装满容积为 x 的背包,有几种方法呢?” -- 这是经典的问题了.她把答案记为 Count(i, x) ,想要

BZOJ2293: 【POJ Challenge】吉他英雄

2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Status] Description 1tthinking 特别喜欢玩‘guitar hero’. 现在有 N (2 ≤ N ≤ 50) 首歌在这个游戏中,他们被标为 1 到 N. 游戏会随机把歌曲分组 P. 更详细的说, 对于 P = <P1, P2, ... PN>, 游戏会在第 i 首之后播放第

BZOJ 2287 【POJ Challenge】消失之物

2287: [POJ Challenge]消失之物 Description ftiasch 有 N 个物品, 体积分别是 W1, W2, ..., WN. 由于她的疏忽, 第 i 个物品丢失了. “要使用剩下的 N - 1 物品装满容积为 x 的背包,有几种方法呢?” -- 这是经典的问题了.她把答案记为 Count(i, x) ,想要得到所有1 <= i <= N, 1 <= x <= M的 Count(i, x) 表格. Input 第1行:两个整数 N (1 ≤ N ≤ 2

BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )

虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要填满容量为 k 的背包 , 则 ans( i , k ) = ∑ f( i - 1, h ) * g( i + 1 , k - h ) ( 0 <= h <= k ) 这样就转化为经典的背包问题了 f( x , k ) = f( x - 1 , k ) + f( x - 1 , k - w( x