DP+bitset

 HDU5716

dp[i][j] = dp[i-1][j-1] && (s[i] in set[j]); 第二维压bitset

 #include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
#define pii pair<int, int>
#define gg puts("gg");
using namespace std;
const int N = 2e6+;
int id(char c){
if(c >= ''&& c <= '') return c-'';
if(c >= 'a'&& c <= 'z') return c-'a'+;
if(c >= 'A'&& c <= 'Z') return c-'A'+;
return -;
}
char s[N], t[];
bitset<> se[], dp;
int main(){
while(gets(s+)){
for(int i = ; i < ; i++) se[i].reset();
dp.reset();
int m, n; scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &m);
scanf(" %s", t);
for(int j = ; t[j]; j++)
se[ id(t[j]) ].set(i);
}
dp.set();
bool tag = true;
for(int i = ; s[i]; i++){
if(id(s[i]) >= )
dp = (dp<<)&se[ id(s[i]) ];
else
dp.reset();
dp.set();
if(dp.test(n))
tag = false, printf("%d\n", i-n+);
}
if(tag) puts("NULL");
getchar();
}
return ;
}

 HDU5745


dp[i][j] = (dp[i-1][j-1]&&s1[i] == s2[j])|(dp[i-2][j-2]&&s1[i] == s2[j-1]&&s1[i-1] == s2[j])

压小的一维T了,压大的一维可以AC.

 #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+;
char s1[N], s2[];
bitset<N> se[], dp[];
int main(){
int t; scanf("%d", &t);
while(t--){
int n, m;
scanf("%d%d", &n, &m);
scanf("%s%s", s1+, s2+);
int l1 = strlen(s1+), l2 = strlen(s2+);
for(int i = ; i < ; i++){
se[i].reset();
for(int j = ; j <= l1; j++)
se[i][j] = (s1[j] == 'a'+i);
}
//se[i][j]: s1的第j个字符是不是i
dp[].set();
for(int i = ; i <= l2; i++){
dp[i%] = (dp[(i+)%]<<)&se[s2[i]-'a'];
if(i >= )
dp[i%] |= (dp[(i+)%]<<)&se[s2[i-]-'a']&(se[s2[i]-'a']<<);
dp[i%][] = ;
}
for(int i = l2; i <= l1; i++)
printf("%d", dp[l2%][i] == );
for(int i = ; i < l2; i++) putchar('');
puts("");
}
return ;
}

HDU5716, HDU5745【dp+bitset】的更多相关文章

  1. 【dp专题】NOIP真题-DP专题练习

    这里学习一下DP的正确姿势. 也为了ZJOI2019去水一下做一些准备 题解就随便写写啦. 后续还是会有专题练习和综合练习的. P1005 矩阵取数游戏 给出$n \times m$矩阵每次在每一行取 ...

  2. [ZPG TEST 118] 最大值【dp+离线】

    题4  最大值(findmax) [题目描述] 找到一个数组的最大值的一种方法是从数组开头从前到后对数组进行扫描,令max=a[0](数组下表从0..N-1),如果a[i]>max,就更新max ...

  3. 【8.14校内测试】【DP专题】

    nlogn做法,dp[i]表示当前长度为i的最长上升子序列末尾元素的值. 不会写lower_bound(qwq,贴一个以前的好看点的代码 #include<iostream>//使用low ...

  4. uva 10069 Distinct Subsequences 【dp+大数】

    题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...

  5. ZOJ 2972 Hurdles of 110m 【DP 背包】

    一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] ...

  6. CodeForces 189A 166E 【DP ·水】

    非常感谢 Potaty 大大的援助使得我最后A出了这两题DP ================================== 189A : 求切分后的ribbon最多的数目,不过要求切分后只能存 ...

  7. 【DP专辑】ACM动态规划总结

    转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 ...

  8. hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分法】

    主题链接:pid=1025">http://acm.acmcoder.com/showproblem.php?pid=1025 题意:本求最长公共子序列.但数据太多. 转化为求最长不下 ...

  9. 愤怒的小鸟【$DP$优化】

    卡常的状压\(DP\),愤怒的小鸟. 其实本来是个很水的状压\(DP\),但因为最后三个点\(n=18\),成功地把我的不可能达到的下界为\(\Omega(2^nn^2)\),紧确的上界为\(O(2^ ...

随机推荐

  1. android TextView加载html内容并加载图片

    package com.example.textviewfromhtml; import java.net.URL; import android.app.Activity; import andro ...

  2. HDU 4315:Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...

  3. java double类型保留两位小数4种方法【转】

    4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberF ...

  4. C类地址

    C类地址第1字节.第2字节和第3个字节为网络地址,第4个字节为主机地址.另外第1个字节的前三位固定为110. C类地址范围:192.0.0.1到223.255.255.255.(第1个字节的二进制值前 ...

  5. 【转】java_web开发入门

    转载地址:http://www.cnblogs.com/xiaoqv/archive/2011/12/10/2283348.html 一.Tomcat服务器常见启动问题:(1).Java_home环境 ...

  6. c#之xml

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  7. Poj(1274),二分图匹配

    题目链接:http://poj.org/problem?id=1274 The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Tota ...

  8. nginx 的限制连接模块limit_zone与limit_req_zone

    转载于:http://storysky.blog.51cto.com/628458/642970/ nginx 上有两个限制连接的模块一个是 limit_zone 另一个是 limie_req_zon ...

  9. muduo库安装

    一.简介 Muduo(木铎)是基于 Reactor 模式的网络库. 二.安装 从github库下载源码安装:https://github.com/chenshuo/muduo muduo依赖了很多的库 ...

  10. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...