CodeForces 314B. Sereja and Periods 思维+简单dp
来源:互联网 发布:facebook直播软件下载 编辑:程序博客网 时间:2024/06/07 01:59
题目
题意:给出不超过100长度的两个字符串a、c,以及两个正整数b、d(b,d<=1e7),求最大的q使得
这个题我的思考角度不大好,唉…
令dp[x]表示c串的第x字符开始匹配,匹配完一个字符串a后,能够匹配多少个整字符串c,并且nex[x]代表下次开始匹配的位置。
状态选取的好…之前一直想的是匹配完一个字符串c后消耗多少a,除了还要考虑下次匹配开始a的位置,还需要考虑b和d…
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<vector>using namespace std;#define all(x) (x).begin(), (x).end()#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)#define mes(a,x,s) memset(a,x,(s)*sizeof a[0])#define mem(a,x) memset(a,x,sizeof a)#define ysk(x) (1<<(x))typedef long long ll;typedef pair<int, int> pii;const int INF =0x3f3f3f3f;const int maxn=100 ;int b,d,lenA,lenC;string a,c;int dp[maxn+10],nex[maxn+10];void cope(int x){ dp[x]=0;nex[x]=x;int use=0; while(use<lenA) { if(a[use ]==c[nex[x]] ) { if(++nex[x]==lenC) { dp[x]++;nex[x]=0; } } use++; }}int main(){ std::ios::sync_with_stdio(false); while(cin>>b>>d) { cin>>a>>c;lenA=a.length(),lenC=c.length(); for0(i,lenC) cope(i); int x=0,num=0; for0(i,b) { num+=dp[x]; x=nex[x]; } num/=d; cout<<num<<endl; } return 0;}
0 0
- CodeForces 314B. Sereja and Periods 思维+简单dp
- CodeForces 314 B.Sereja and Periods 思维+简单dp【转】
- CodeForces 314B - Sereja and Periods 很有思维的DP
- CodeForces 314 B.Sereja and Periods(dp)
- CF 314B: Sereja and Periods
- Codeforceds 315D Sereja and Periods【思维+Dp】
- Codeforces 401B Sereja and Contests(DP)
- Codeforces #187 (Div. 1) B. Sereja and Periods && Hihocoder 1355 (字符串匹配倍增好题)
- Codeforces 315E Sereja and Subsequences【思维+Dp】
- CodeForces #352B.Jeff and Periods
- codeforces B. Sereja and Contests
- Codeforces 368C Sereja and Algorithm【思维】
- Codeforces 426C Sereja and Swaps【思维】
- Codeforces 315C Sereja and Contest【思维】
- Codeforces 426E Sereja and Two Sequences【思维+Dp+二分】好题!
- codeforces 315 B.Sereja and Array
- CodeForces 315B Sereja and Array
- codeforces 401B - Sereja and Contests
- csdn如何转载别人的文章
- 条款二十四:了解virtual functions、multiple inheritance、virtual base class、runtime type identification的成本
- 搭建web项目结合spring+cxf的webservice服务
- 初学主席树
- Spark word count 实例
- CodeForces 314B. Sereja and Periods 思维+简单dp
- 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
- Leetcode 122: Best Time to Buy and Sell Stock II
- spring4+mybatis3+velocity+mysql+gradle
- JSP学习笔记---pageContext对象
- HDU 2588 NOJ 1126 GCD 欧拉函数应用问题
- Redis初识(二)
- Visual studio 2015(VS2015)的下载和安装,以及安装VS2015中的C++
- 【框架MFC】限制单文档和多文档窗口范围最小值(设置窗口宽度和高度的下限)