Another Meaning
来源:互联网 发布:苏联赫鲁晓夫知乎 编辑:程序博客网 时间:2024/06/05 10:43
链接:http://acm.hust.edu.cn/vjudge/problem/435534/origin
Today, ?? is chating with MeiZi online, MeiZi sends a sentence A to ??. ?? is so smart that he knows the word B in the sentence has two meanings. He wants to know how many kinds of meanings MeiZi can express.
题意:字符串a中出现的b可以被修改(理解成换成*比较方便),当然可以不修改。问共有多少种方案。
分析:一开始想用贪心的,但是情况太复杂(出现b的一部分和a链接后还可以匹配等)不太好讨论,所以采用dp,把问题分解成从1到n,n《=a的长度,的字符可以有多少方案,再之后的b的长度的字符串是否可以替换,可以就是(n+len(b)-1)位的种数(因为长度不够,没达到替换要求,视为不替换的方案数)加上替换后的n的种数(替换为*)。最后dp【len(a)】即为结果。(对了,由于是字串是动态的,不能用kmp优化,要用哈希来优化,不知道暴力匹配会不会超时。。。。)
题解:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <map>#include <string>#include <cstring>#include <functional>#include <cmath>#include <cctype>#include <cfloat>#include <climits>#include <complex>#include <deque>#include <list>#include <set>#include <utility>#define rt return#define fr freopen("in.txt","r",stdin)#define fw freopen("out.txt","w",stdout)#define ll long long#define ull unsigned long long#define detie ios_base::sync_with_stdio(false);cin.tie(false);cout.tie(false)#define pii pair<int,int>#define lowbit(x) x&(-x)using namespace std;#define maxi 0x3f3f3f3f#define MAX 100020int t, dp[MAX], al, bl, cases;char a[MAX], b[MAX];ull B = 100000007;ull MOD = 1000000007;int main(){//fr;detie;cin >> t;while (t--){cin >> a >> b;al = strlen(a);bl = strlen(b);ull ah = 0, bh = 0, t = 1;for (int i = 0; i < bl; i++){t *= B;ah = ah*B + a[i];bh = bh*B + b[i];}memset(dp, 0, sizeof dp);fill(dp, dp + bl, 1);for (int i = 0; i + bl <= al; i++){dp[i + bl] = dp[i + bl - 1];if (ah == bh)dp[i + bl] = (dp[i + bl] + dp[i]) % MOD;if (i + bl < al)ah = ah*B + a[i + bl] - t*a[i];}printf("Case #%d: %d\n", ++cases, dp[al]);}rt 0;}
0 0
- Another Meaning
- Another Meaning
- HDU 5763 Another Meaning
- HDU5763 Another Meaning
- HDU 5763 Another Meaning
- HDU 5763 Another Meaning
- HDOJ 5763 Another Meaning
- 【HDU】5763 Another Meaning
- hdu 5763 Another Meaning
- HDOJ 5763 Another Meaning
- DP-HDU-5763-Another Meaning
- HDU Another Meaning DP+KMP
- HDU5763 Another Meaning动态规划
- hdu5763 Another Meaning(kmp+dp)
- HDU 5763 Another Meaning (DP)
- 多校4 Another Meaning 5763
- 【47.92%】【hdu 5763】Another Meaning
- hdu5763 Another Meaning(DP+KMP)
- [深入理解Android卷一全文-第三章]深入理解init
- 旋转卡壳->POJ2079
- springmvc传递json map数据
- LeetCode 324. Wiggle Sort II
- Python 包管理工具
- Another Meaning
- MyEclipse2014创建Maven项目pom.xml文件报Plugin execution not covered by lifecycle configuration
- [深入理解Android卷一 全文-第二章]深入理解JNI
- 网站组成模块
- Crash日志,分析专用
- hive-2.0安装
- Redis探索之旅(2)- 在Windows下搭建单实例Redis服务器
- 在 Laravel 中使用 Laravel Searchy 扩展包实现基于数据库的轻量级搜索功能
- hadoop+hbase on mesos环境搭建