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

标解是拿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. node express 静态资源

    实例代码 const express = require('express') const path = require('path') const app = express() app.use(e ...

  2. centos6.5 squid安装

    squid作用 1正向代理 标准的代理缓冲服务器,须在每一个内部主机的浏览器上明确指明代理服务器的IP地址和端口号. 透明代理缓冲服务器,代理操作对客户端的浏览器是透明的(即不需指明代理服务器的IP和 ...

  3. 并发连接MySQL

    先吐槽一下libmysqlclientAPI的设计, 多个线程同时去connect居然会core掉. 后来Google了一番, 才发现mysql_real_connect不是线程安全的, 需要一些额外 ...

  4. Linux安装Apache常见报错(一)

    启动Apache提示报错:Could not reliably determine the server's fully qualified domain name, using localhost, ...

  5. 2017软工实践K班总结

    回首一学期的软工实践,从暑假开始陆续布置作业,经历个人.结对与团队等大小作业.也经历了不少同学被吓跑.第一周就退选的情况,能坚持下来的都是胜利者,至少你们有一颗愿意挑战的心.首先感谢助教谢涛付出的巨大 ...

  6. 使用HttpUtils完成Http Basic 认证

    调用声网(agora)的远程接口(Restful Api)时,对方需要使用Basic Auth的方式进行认证(需要输入用户名和密码). 一,使用Postman完成基于Basic Auth的Http认证 ...

  7. hdu1421_搬寝室

    题目:搬寝室 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 #include<stdio.h> #include<algor ...

  8. MyBatis源码分析1 参数映射分析

    首先我们拿出之前的代码,在如图位置打上断点,开始调试 我们规定了一个mapper接口,而调用了mapper接口的getEmpByIdAndLastName,我们并没有实现这个接口,这是因为Mybati ...

  9. git遇到的问题 .Git: There is no tracking information for the current branch.

    1.Git: There is no tracking information for the current branch. 在执行git pull的时候,提示当前branch没有跟踪信息: git ...

  10. keyvalue对RDD s

    scala> val input =sc.textFile("/home/simon/SparkWorkspace/test.txt")input: org.apache.s ...