|BZOJ 1633|字符串DP|[Usaco2007 Feb]The Cow Lexicon 牛的词典
来源:互联网 发布:insert into多个数据 编辑:程序博客网 时间:2024/05/20 21:46
BZOJ 1633
Luogu 2875
from: USACO 2007 Jan Sliver(USACO刷题第13题)
刚开始根本没想到DP,什么kmp,AC自动机,后缀数组都想了。。看了题解才知道
解决字符串的几大武器:(字符串DP,字符串Hash,KMP,AC自动机,后缀家族……)
本题设
刚开始想了个超时的方法。。然后发现其实直接写就行了。。还是太弱
方程:
其中
初始化
#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<vector>#define ms(i, j) memset(i, j, sizeof i)#define LL long longusing namespace std;const int MAXW = 600 + 5, MAXL = 300 + 5;char dic[MAXW][MAXL], s[MAXL];int n, L, f[MAXL];void clear() {}void init() { clear(); scanf("%s", s+1); for (int i=1;i<=n;i++) scanf("%s", dic[i]+1);}void solve() { for (int i=1;i<=L;i++) { f[i] = i; for (int j=1;j<=n;j++) { int len = strlen(dic[j]+1); int k, cnt = 0; for (k=i;k>0;k--) { if (dic[j][len]==s[k]) len--; else cnt++; if (len==0) break; } if (len==0) f[i] = min(f[i], f[k-1]+cnt); } } printf("%d\n", f[L]);}int main() { #ifndef ONLINE_JUDGE freopen("1.in", "r", stdin);freopen("1.out", "w", stdout); #endif while (scanf("%d%d", &n ,&L)==2) init(), solve(); return 0;}
阅读全文
0 0
- |BZOJ 1633|字符串DP|[Usaco2007 Feb]The Cow Lexicon 牛的词典
- BZOJ 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- 【BZOJ1633】[Usaco2007 Feb]The Cow Lexicon 牛的词典【DP】
- BZOJ1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 DP
- 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典(DP)
- bzoj1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典
- BZOJ1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典
- pku 3267 The Cow Lexicon(很经典的字符串DP)
- poj3267--The Cow Lexicon(dp:字符串组合)
- BZOJ 1631: [Usaco2007 Feb]Cow Party
- 【BZOJ 1631】 [Usaco2007 Feb]Cow Party
- BZOJ 1631: [Usaco2007 Feb]Cow Party
- BZOJ 1631: [Usaco2007 Feb]Cow Party spfa
- BZOJ 1631: [Usaco2007 Feb]Cow Party
- POJ3267 The Cow Lexicon DP
- POJ3267 The Cow Lexicon, DP
- POJ3267 The Cow Lexicon DP
- OJ.1996: C语言实验——打印菱形
- hibernate笔记-011-单向一对多映射
- CFileDialog用法
- 关于arcgis版本问题的讲解例如CPG
- windows下检测软件运行状态。脚本
- |BZOJ 1633|字符串DP|[Usaco2007 Feb]The Cow Lexicon 牛的词典
- JVM相关文章聚合
- Kotlin-07.返回和跳转(return/break/continue)
- Win10中Ubuntu优化配置
- Scala基础—Trait使用示例
- Android开发-多线程
- Retrofit + RxJava + OkHttp 让网络请求变的简单-封装篇
- javaScript系列之事件处理器以(三)
- Hadoop之HDFS(二)