这题现场的数据出水了,暴力就能搞过。

标解是拿bitset做,转移的时候用bitset优化过的操作(与或非移位)来搞,复杂度O(N*M/w) w是字长

第一份标程的思路很清晰,然而后来会T。

 /*--------------------------------------------------------------------------------------*/

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
const int maxn = 1e5+;
const int maxm = +; bitset <maxn> dp[],D[];
char s[maxn],p[maxm]; void solve()
{
for(int i=;i<;i++) D[i].reset();
for(int i=;i<N;i++) D[s[i]-'a'][i] = ; dp[].reset();
dp[].reset();
dp[].reset();
for(int i=;i<N;i++) dp[][i] = ; for(int i=;i<M;i++)
{
int cur = p[i]-'a';
dp[(i+)%] = dp[i%] & D[cur]>>i;
if(i > )
{
int lst = p[i-]-'a';
dp[(i+)%] |= dp[(i+)%] & D[cur]>>i- & D[lst]>>i;
}
} for(int i=;i<N;i++)
{
if(dp[M % ][i] == ) putchar('');
else putchar('');
}
puts("");
} int main()
{
//freopen("1012.in","r",stdin);
//freopen("1012.bitset.out","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d%d ",&N,&M);
scanf("%s%s",s,p);
solve();
}
}

HDU5745-La Vie en rose-字符串dp+bitset优化的更多相关文章

  1. hdu5745 La Vie en rose 巧妙地dp+bitset优化+滚动数组减少内存

    /** 题目:hdu5745 La Vie en rose 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5745 题意:题目给出的变换规则其实就是交换相邻 ...

  2. HDU 5745 La Vie en rose 暴力

    La Vie en rose 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5745 Description Professor Zhang woul ...

  3. hdu 5745 La Vie en rose(2016多校第二场)

    La Vie en rose Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. HDU 5745 La Vie en rose

    La Vie en rose Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. hdu 5745 La Vie en rose DP + bitset优化

    http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...

  6. HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场

    题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...

  7. La Vie en rose (模拟)

    #include<bits/stdc++.h> using namespace std; ; ; int T, n, m; char str1[maxm], str2[maxn]; int ...

  8. hdu5745--La Vie en rose (DP+bitset)

    好题,学到新姿势! 题意:给两个字符串 a 和 b ,b可以进行变换,规则是可以任意交换相邻两个字符的位置,但是不可以有交叉(例如3和4交换,5和6交换 互不影响,但是2和3,3和4就不可以).求a中 ...

  9. SPOJ:Harbinger vs Sciencepal(分配问题&不错的DP&bitset优化)

    Rainbow 6 is a very popular game in colleges. There are 2 teams, each having some members and the 2 ...

随机推荐

  1. Webpack+Typescript 简易配置

    教程:https://www.cnblogs.com/yasepix/p/9294499.html http://developer.egret.com/cn/github/egret-docs/ex ...

  2. 朱晔和你聊Spring系列S1E10:强大且复杂的Spring Security(含OAuth2三角色+三模式完整例子)

    Spring Security功能多,组件抽象程度高,配置方式多样,导致了Spring Security强大且复杂的特性.Spring Security的学习成本几乎是Spring家族中最高的,Spr ...

  3. Django Rest framework基础使用之 serializer

    rest-framework文档地址:http://www.django-rest-framework.org/ Django Rest framework是一个非常强大且灵活的工具包,用于构建web ...

  4. 关于getHibernateTemplate().get()方法

    返回的对象值唯一,方法带有两个参数 第一个是意图查询实体的Class 如User.Class  ;第二个参数是该实体在数据库中对应的主键值,而且参数的类型要和映射文件相对应. 如 Role role ...

  5. 大连CCPC D - A Simple Math Problem

    #include<iostream> #include<string.h> #include<stdio.h> #include<algorithm> ...

  6. codeforces#687 B. Remainders Game

    题意:给出n个数,和一个数p,问你在知道 x%ai  的情况下,能不能确定x%p的值 结论:当n个数的最小公倍数是p的倍数时,可以确定 代码: #include <bits/stdc++.h&g ...

  7. 分享一个小设置-项目启动时服务器指向本地IIS

    背景,在X公司做的一个网站登录时需要域名的支持,就是说浏览器地址栏在localhost+端口号的形式下无法实现登录(必须是xxxx域名的形式), 但是很多时候都会先在线下进行测试,既然本地没有线上的环 ...

  8. 输入input

    用input接收到的类型全部都是字符串!!! 要查看变量类型,可以使用type()模块: 字符串不能和数字进行比较,因此如果输入是以input方式输入的,需要先转换成数字格式:

  9. gin框架学习手册

    前言 gin框架是go语言的一个框架,框架的github地址是:https://github.com/gin-gonic/gin 转载本文,请标注原文地址:https://www.cnblogs.co ...

  10. Oracle 表分区(Partition)

    表分区功能能够改善应用程序性能,提高数据库可管理性和可用性,是数据库管理非常关键的技术.数据库通过使用分区提高查询性能,简化日常管理维护工作. 1 分区优点 1) 减少维护工作量,独立管理每个表分区比 ...