【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 ) 表示前 ...
随机推荐
- TP框架项目部署linux大小写问题
TP框架项目部署linux大小写问题
- ffmpeg Win8移植记(二)
接着上回说,http://www.cnblogs.com/zjjcy/p/3384517.html 上回移植了ffmpeg在ARM上面,只是纯C的代码,没有做汇编的优化.因为ffmpeg的ARM汇编是 ...
- 05-maven学习-构建web项目
1,新增maven项目 然后输入相应包名,项目名,创建如下项目 发现以上有报错,需要进行如下操作: 下面文章转载自:http://blog.csdn.net/zhshulin/article/deta ...
- Drupal 7 driver for SQL Server and SQL Azure
Drupal 7 driver for Microsoft SQL Server database engines. It supports both SQL Server (version 2008 ...
- MySQL数据库字符集由utf8修改为utf8mb4一例
对于mysql 5.5 而言,如果不设定字符集,mysql默认的字符集是 latin1 拉丁文字符集: 为了统一管理和应用开发的方便,一般都会统一将操作系统,客户端,数据库各方面的字符集都设置为 ut ...
- mysql root用户密码个性
对名为“mysql”数据库下的表“user”进行操作如下语句:update user set password=PASSWORD("your_password") where us ...
- C++方式解析时间字符串和计算时间
#include "StdAfx.h"#include "MySetTimeByVT.h" #include <ATLComTime.h>#incl ...
- with(上下文的用法)以及其他知识点
一.上下文 class Sxw(object): def __enter__(self): '''进入''' print("你好啊") def __exit__(self, exc ...
- 常用maven 仓库地址
maven下载jar的时候会去寻国外的地址,因此造成了下载jar很缓慢,影响开发效率,于是就出现maven镜像地址,可以使我们开发人员迅速下载相关的jar. 在maven的config的setting ...
- nginx 反向代理 配置 https 实现http https同时存在 经测试 支持location 规则
server { listen ssl; #监听443端口 server_name www.app01.com; ssl on; #启用ssl加密 ssl_certificate /etc/cert/ ...