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

标解是拿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. 前端自动化 shell 脚本命令 与 shell-node 脚本命令 简单使用 之 es6 转译

    (背景: 先用 babel 转译 es6 再 用 browserify 打包 模块化文件,来解决浏览器不支持模块化 )(Browserify是一个让node模块可以用在浏览器中的神奇工具) 今天折腾了 ...

  2. Python学习第六篇——字典中的键和值

    favorite_language ={ "jen":"python", "sarah":"c", "edwa ...

  3. urllib库

    python内置的最基本的HTTP请求库,有以下四个模块: urllib.request 请求模块 urllib.error 异常处理模块 urllib.parse url解析模块 urllib.ro ...

  4. MySQL导出数据,并转存到Excel表格中

    从数据库中导出数据的方法,这里就不提了,网上有很多方法,如果闲麻烦,可以看一下这个:mysql导出数据 其实使用最简单的下面这个语句: mysql > select * from demo in ...

  5. Android下的软件合集

    在平常使用Android手机的时候,选择一个好的软件可以做到事半功倍的效果,所以在此总结一下,加速我们的工作与生活效率 1) ConnectBot ConnectBot是一个Android操作系统上的 ...

  6. 【Python3练习题 016】 猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个。第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。

    这题得倒着推.第10天还没吃,就剩1个,说明第9天吃完一半再吃1个还剩1个,假设第9天还没吃之前有桃子p个,可得:p * 1/2 - 1 = 1,可得 p = 4.以此类推,即可手算出. 代码思路为: ...

  7. opencv2\flann\matrix.h(69): error C2059: 语法错误:“,”

    在提示错误的matrix.h头文件中,修改一下,在free前加上_ ,即FLANN_DEPRECATED void _free() .

  8. .Net批量插入数据

    1. 一般我们普通数据插入是这样的: 现在我们写一个控制台程序用常规办法添加10000条数据. //以下是批量插入数据的办法 //连接字符串 string str = "Server=.;D ...

  9. Quartz框架学习(1)—核心层次结构

    Quartz框架学习 Quartz(任务调度)框架的核心组件: job:任务.即任务调度行为中所要调度的对象. trigger:触发器.是什么促使了一个任务的调度?当然是时间.这也算事件驱动类型程序. ...

  10. 简单易懂的softmax交叉熵损失函数求导

    参考: https://blog.csdn.net/qian99/article/details/78046329