【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 ) 表示前 ...
随机推荐
- HDU4300-Clairewd’s message(KMP前缀匹配后缀)
Clairewd's message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- TP框架模板中IF Else 如何使用?
TP框架模板中IF Else 如何使用? 截个图吧 如果效果出不来,一般就是条件写错了!!!
- Python list删除元素
pop()方法 pop(n) 从list删除元素Paul同学刚来几天又要转走了,那么我们怎么把Paul 从现有的list中删除呢?如果Paul同学排在最后一个,我们可以用list的pop()方法删除: ...
- oracle 两表关联查询
oracle 两表关联查询 CreationTime--2018年7月4日17点27分 Author:Marydon 情景描述 查询学生表student,sname,sex,age信息及所在班级c ...
- java注解,通过反射解析注解,模仿hibernate,获取sql语句。
常用注解: 自定义注解,标准格式: 1,target:注解作用域 2,Retention:声明周期 运行子类继承,但是子类继承只能作用到类注解,字段注解,是继承不了的. 使用注解:通过下面这种方式,为 ...
- 【微信小程序】再次授权地理位置getLocation+openSetting使用
写在前面:在tarbar主页面,再次授权JS代码请放在onshow里面:在详情页(非一级主页面),再次授权JS代码请放在onReady里面,具体原因我前面博客讲了的. 我们知道: 1.微信的getLo ...
- 为什么我没有拔出钥匙 ——开锁引发的程序bug解决方案的思考
http://blog.csdn.net/wojiushiwo987/article/details/8851204为什么我没有拔出钥匙 ——开 ...
- centos6.3下yum安装redis
我得是centos 6.3,如果直接用yum安装redis,报错,如下: [root@CentOS6 etc]# yum install redis Loaded plugins: fastestmi ...
- 火狐浏览器(firefox)中js要注意的问题
1.出现错误调用error方法或者ajax请求了多次,那么极有可能是异步请求的原因. 添加 async : false , -> async. 默认是 true,即为异步方式,$.aja ...
- CSC时无法找到C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib
偶然用到CSC编译c#程序,出现如下问题: warning CS1668: “LIB 环境变量”中指定的搜索路径“C:\Program Files\Microsoft SDKs\Wind ...