bzoj1622 名字的能量
Description
约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1≤M≤100)个代表能量的字符串.每个字符串由不超过30个字体构成,同样不存在空字符串.一个奶牛的名字蕴含多少个能量字符串,这个名字就有多少能量.所谓“蕴含”,是指某个能量字符串的所有字符都在名字串中按顺序出现(不一定一个紧接着一个).
所有的大写字母和小写字母都是等价的.比如,在贝茜的名字“Bessie”里,蕴含有“Be”
“sI”“EE”以及“Es”等等字符串,但不蕴含“lS”或“eB”.请帮约翰计算他的奶牛的名字的能量.
Input
第1行输入两个整数N和M,之后N行每行输入一个奶牛的名字,之后M行每行输入一个能量字符串.
Output
一共N行,每行一个整数,依次表示一个名字的能量.
Sample Input
5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
INPUT DETAILS:
There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont
INPUT DETAILS:
There are 5 cows, and their names are "Bessie", "Jonathan",
"Montgomery", "Alicia", and "Angola". The 3 good strings are "se",
"nGo", and "Ont".
Sample Output
1
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".
1
2
0
1
OUTPUT DETAILS:
"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains
both "nGo" and "Ont", Alicia contains none of the good strings, and
"Angola" contains "nGo".
思路: 这题可以暴力模拟做,时间复杂度最多是$O(n*m*1030)$
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define R register int 4 #define rep(i,a,b) for(R i=a;i<=b;i++) 5 #define Rep(i,a,b) for(R i=a;i>=b;i--) 6 #define ms(i,a) memset(a,i,sizeof(a)) 7 int const N=1001; 8 char s[N][N],t[N][N]; 9 int n,m; 10 int pd(int x,int y){ 11 int k=0; 12 for(int i=0;t[y][i];i++){ 13 int check=0; 14 for(int j=k;s[x][j];j++){ 15 if(s[x][j]==t[y][i]){ 16 k=j+1;check=1;break; 17 } 18 } 19 if(!check) return 0; 20 } 21 return 1; 22 } 23 24 int main(){ 25 scanf("%d%d",&n,&m); 26 rep(i,0,n-1) scanf("%s",s[i]); 27 rep(i,0,n-1) 28 for(int j=0;s[i][j];j++) if(s[i][j]<=90) s[i][j]+=32; 29 rep(i,0,m-1) scanf("%s",t[i]); 30 rep(i,0,m-1) 31 for(int j=0;t[i][j];j++) if(t[i][j]<=90) t[i][j]+=32; 32 rep(i,0,n-1){ 33 int ans=0; 34 rep(j,0,m-1) if(pd(i,j)) ans++; 35 printf("%d\n",ans); 36 } 37 return 0; 38 }