BZOJ3297: [USACO2011 Open]forgot DP+字符串
Description
Input
Output
*第1行:密码
Sample Input
a??l?ban???????
apple
cow
farmer
banana
bananas
pies
Sample Output
Solution
一开始没啥想法就打了一个搜索,复杂度$O$(期望能过),结果T的很稳
想了想其他做法发现其实可以直接$dp$维护字典序最小
$string$都不会用了...QAQ
#include <bits/stdc++.h> using namespace std ; int L , n ;
char s[ ] , ans[ ] ;
string a[ ] ;
string f[ ] ;
int len[ ] ; bool check( int x , int t ) {
for( int i = ; i < len[ t ] ; i ++ ) {
if( a[ t ][ i ] != s[ x + i ] && s[ x + i ] != '?' ) return ;
}
return ;
} int main() {
scanf( "%d%d" , &L , &n ) ;
scanf( "%s" , s + ) ;
for( int i = ; i <= n ; i ++ ) {
cin >> a[ i ] ;
len[ i ] = a[ i ].length() ;
}
for( int i = ; i <= L ; i ++ ) {
for( int j = ; j <= n ; j ++ ) {
int t = i - len[ j ] ;
if( t < ) continue ;
if( t && f[ t ] == "" ) continue ;
if( check( t + , j ) ) {
if( f[ i ] == "" || f[ i ] > f[ t ] + a[ j ] )
f[ i ] = f[ t ] + a[ j ] ;
}
}
}
cout << f[ L ] << endl ;
return ;
}
BZOJ3297: [USACO2011 Open]forgot DP+字符串的更多相关文章
- bzoj3297[USACO2011 Open]forgot(dp + string)
3297: [USACO2011 Open]forgot Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 137 Solved: 94[Submit] ...
- BZOJ3297: [USACO2011 Open]forgot
3297: [USACO2011 Open]forgot Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 54 Solved: 38[Submit][ ...
- BZOJ3297: [USACO2011 Open]forgot(背包)
3297: [USACO2011 Open]forgot Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 189 Solved: 126[Submit ...
- 3297: [USACO2011 Open]forgot
3297: [USACO2011 Open]forgot Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 69 Solved: 51[Submit][ ...
- 【bzoj3297】[USACO2011 Open]forgot STL+dp
题目描述 发生了这么多,贝茜已经忘记了她cowtube密码.然而,她记得一些有用的信息. 首先,她记得她的密码(记为变量P)长度为L(1 <= L<=1,000)字符串,并可以被分成 一个 ...
- 【BZOJ】3297: [USACO2011 Open]forgot(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=3297 这题拖了很久呢... 很久以前写了个dfs,,但是tle了..... 然后一直想dp想不出来, ...
- Codeforces 176B (线性DP+字符串)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...
- Codeforces Round #367 (Div. 2) A B C 暴力 二分 dp(字符串的反转)
A. Beru-taxi time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- HDU 2089 数位dp/字符串处理 两种方法
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- python center() 函数
center Python center() 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串.默认填充字符为空格. 语法 center()方法语法: str.center(widt ...
- UILabel富文本 段落格式以及UILabel添加图片
之前文本整理有一点乱,这边重新整理一下,下面是效果图,一共两个UILabel, 富文本整理: /*NSForegroundColorAttributeName设置字体颜色,对象UIColor; NSP ...
- testng入门教程14数据驱动(不同文件)
数据与test脚本不在同一文件时,下面是数据: package data_driver_two_parts; import org.testng.annotations.DataProvider; p ...
- POJ 3461 Oulipo(KMP,模式串在主串中出现次数 可重叠)
题意:给你两个字符串p和s,求出p在s中出现的次数. 显然,我们要先把模式串放到前面,之后主串放后面,中间隔开,这样就可以根据前缀数组的性质来求了. 我先想直接把p接到s前面,之后求Next数组对st ...
- java tar.gz文件生成
/** * 压缩文件成Gzip格式,Linux上可使用 * 压缩文件夹生成后缀名为".gz"的文件并下载 * @param folderPath,要压缩的文件夹的路径 * @par ...
- nginx之全局设置,location,虚拟主机,日志管理
nginx之全局设置,location,虚拟主机,日志管理 worker_processes 1;//子进程,cpu数*核数 ****************全局设置************** ** ...
- 持续集成之三:Maven私服Nexus使用
环境 Red Hat Enterprise Linux Server release 7.3 (Maipo) jdk1.7.0_80 apache-tomcat-7.0.90 mysql-5.7.23 ...
- java commons.lang3 ArrayUtils使用
java commons.lang3 ArrayUtils使用import org.apache.commons.lang3.ArrayUtils; /** *数组追加数组,不重复 */ public ...
- Qt之美(一):D指针/私有实现
The English version is available at: http://xizhizhu.blogspot.com/2010/11/beauty-of-qt-1-d-pointer-p ...
- MySQL Crash Course #03# Chapter 5. 6 排序. BETWEEN. IS NULL
索引 排序检索的数据 SQL 过滤 vs. 应用程序过滤 简单 Where 补充:大小写敏感. BETWEEN. IS NULL Sorting Retrieved Data mysql> SE ...