【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622
这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!!
1400ms不科学!
设f[i][j]为名字i位置的j字母最早出现的位置(向后)
则
f[i][j]=f[i+1][j]
f[i][a[i+1]]=i+1
那么就可以递推出,然后查找即可。。
但是大量的memcpy导致很慢啊。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=1005;
int f[N][265], n, m, ans;
char a[N][N], md[105][40]; int main() {
read(n); read(m);
for1(i, 1, n) { scanf("%s", a[i]+1); for1(j, 1, strlen(a[i]+1)-1) if(a[i][j]>='A'&&a[i][j]<='Z') a[i][j]=a[i][j]-'A'+'a'; }
for1(i, 1, m) { scanf("%s", md[i]); for1(j, 0, strlen(md[i])-1) if(md[i][j]>='A'&&md[i][j]<='Z') md[i][j]=md[i][j]-'A'+'a'; }
for1(i, 1, n) {
CC(f, 0);
for3(j, strlen(a[i]+1)-1, 0) {
memcpy(f[j], f[j+1], sizeof(f[j]));
f[j][(int)a[i][j+1]]=j+1;
}
ans=m;
for1(j, 1, m) {
int t=0;
for2(k, 0, strlen(md[j])) {
t=f[t][(int)md[j][k]];
if(!t) { --ans; break; }
}
}
printf("%d\n", ans);
}
return 0;
}
Description
Input
Output
Sample Input
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
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".
HINT
Source
【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)的更多相关文章
- bzoj 1622: [Usaco2008 Open]Word Power 名字的能量【模拟】
模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; ...
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
题目 1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved ...
- BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...
- 1622: [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 370 Solved: 18 ...
- [Usaco2008 Open]Word Power 名字的能量
1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 408 Solved: 19 ...
- bzoj1622 [Usaco2008 Open]Word Power 名字的能量
Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只奶牛的名字由不超过1000个字待构成,没有一个名字是空字体串, 约翰有一张“能量字符串表”,上面有M(1 ...
- BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )
-------------------------------------------------------------------- #include<cstdio> #include ...
- BZOJ 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛( dp )
一道水 dp ...然后我一开始用 BFS ...结果 MLE 了... dp[ i ][ j ][ k ] 由它四个方向上的 k - 1 转移. -------------------------- ...
- BZOJ 1592: [Usaco2008 Feb]Making the Grade 路面修整( dp )
最优的做法最后路面的高度一定是原来某一路面的高度. dp(x, t) = min{ dp(x - 1, k) } + | H[x] - h(t) | ( 1 <= k <= t ) 表示前 ...
随机推荐
- webpack 编译模板文件
1.项目结构 安装loader: npm i html-loader --save-dev npm i ejs-loader --save-dev 2.模板文件layer.tpl <div cl ...
- STDIN_FILENO vs stdin
数据类型不一致:stdin类型为 FILE*STDIN_FILENO类型为 int 使用stdin的函数主要有:fread.fwrite.fclose等,基本上都以f开头使用STDIN_FILENO的 ...
- 首次使用JBoss流程(windows下)
1.首先应该明白JBoss分为社区版(AS)和企业版(EAP),其中社区版已经改名wildfly(难道是野苍蝇的意思?),企业版对个人开发者免费下载使用, 这里由于公司要求,我用的是jboss-eap ...
- iOS开发-代码片段(Code Snippets)提高开发效率
简介 在 XCode4 引入了一个新特性,那就是“代码片段(Code Snippets)”.对于一些经常用到的代码,抽象成模板放到 Code Snippets 中,使用的时候就只需要键入快捷键就可以了 ...
- 利用DM工具Weka进行数据挖掘(分类)的完整过程
利用DM工具Weka进行数据挖掘(分类)的完整过程:
- stm32 堆和栈(stm32 Heap & Stack)
关于堆和栈已经是程序员的一个月经话题,大部分有是基于os层来聊的. 那么,在赤裸裸的单片机下的堆和栈是什么样的分布呢?以下是网摘: 刚接手STM32时,你只编写一个 int main() { whil ...
- ToString(“N2”)和ToString(“0.00”)之间的区别
看来N会包含数千个分隔符,而0.00则不会. N2将以500.00的方式工作,但是当您有5000.00时,N2将显示为 5,000.00 代替 5000.00 If you do this inste ...
- shell中的find和xargs详细解析
- 利用docker-maven-plugin快速交测
目的 由开发环境交测的时候,通过docker镜像简化环境搭建及项目部署的过程. 环境描述 项目开发环境: windowns7 在windowns7中通过VMware Workstation安装Cent ...
- openWRT学习之LUCI之中的一个helloworld演示样例
备注1:本文 讲述的是原生的openWRT环境下的LUCI 备注2:本文參考了诸多资料.感谢网友分享.參考资料: http://www.cnblogs.com/zmkeil/archive/2013/ ...