HDU5745-La Vie en rose-字符串dp+bitset优化
这题现场的数据出水了,暴力就能搞过。
标解是拿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优化的更多相关文章
- hdu5745 La Vie en rose 巧妙地dp+bitset优化+滚动数组减少内存
/** 题目:hdu5745 La Vie en rose 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5745 题意:题目给出的变换规则其实就是交换相邻 ...
- HDU 5745 La Vie en rose 暴力
La Vie en rose 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5745 Description Professor Zhang woul ...
- 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 ...
- 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 ...
- hdu 5745 La Vie en rose DP + bitset优化
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...
- HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场
题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...
- La Vie en rose (模拟)
#include<bits/stdc++.h> using namespace std; ; ; int T, n, m; char str1[maxm], str2[maxn]; int ...
- hdu5745--La Vie en rose (DP+bitset)
好题,学到新姿势! 题意:给两个字符串 a 和 b ,b可以进行变换,规则是可以任意交换相邻两个字符的位置,但是不可以有交叉(例如3和4交换,5和6交换 互不影响,但是2和3,3和4就不可以).求a中 ...
- 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 ...
随机推荐
- 原生JS实现三级联动
代码实现 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- 配置Nginx虚拟主机
实验环境 一台最小化安装的CentOS 7.3虚拟机 配置基本环境 1. 安装nginx yum install -y epel-* yum isntall -y nginx vim 2. 建立虚机主 ...
- 体验usually.js的管道函数——pipe函数
体验usually.js的管道函数——pipe函数 usually.js 是一个面向现代 Web 开发的 JavaScript 函数库,基于 ES6 开发.最新版本2.4.1,最新版本usually. ...
- Centos7之Systemd(Service文件)详解
一.开机启动 对于那些支持 Systemd 的软件,安装的时候,会自动在/usr/lib/systemd/system目录添加一个配置文件. 如果你想让该软件开机启动,就执行下面的命令(以httpd. ...
- Python_每日习题_0006_斐波那契数列
程序设计: 斐波那契数列(Fibonacci sequence),从1,1开始,后面的每一项等于前面两项之和. 图方便就递归实现,图性能就用循环. # for 循环 target = int(inpu ...
- 解决ImportError: cannot import name 'webdriver' from 'selenium' (C:\Users\Mr.Su\PycharmProjects\***\venv\selenium.py)
报错信息如下图所示: 解决方案:将项目根目录下的自己创建的selenium.py文件重命名.
- noode inquirer
一. 由于交互的问题种类不同,inquirer为每个问题提供很多参数: type:表示提问的类型,包括:input, confirm, list, rawlist, expand, checkbox, ...
- java对象的四种引用:强引用、软引用、弱引用和虚引用
在JDK1.2之前,创建的对象只有在处于可触及(reachable)的状态下,才能被程序使用.也就是说,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.垃圾回收器一旦发现这些无用对象,就会对 ...
- 本地上传项目到github
https://www.cnblogs.com/rosej/p/6056467.html(copy)
- IntelliJ IDEA启动Tomcat后,却无法访问Tomcat主页 等一系列问题
1.IntelliJ IDEA启动Tomcat后,却无法访问Tomcat主页 转:http://www.myexception.cn/other/1998827.html https://blog.c ...