题目链接:点击进入
题目


题意
给你文本串 s ,模式串 t ,要求给 s 重新排序,使排序后的文本串出现尽可能多的模式串 t 。输出排序后的 s 。
( 字符串为 01 串 )
思路
按照 kmp 匹配的模式来构造,尽可能满足 s [ i ] = t [ j ] ,若是满足不了啦,那就将剩下的位置剩下的数随便匹配。
代码
// Problem: Oulipo
// Contest: Virtual Judge - POJ
// URL: https://vjudge.net/problem/POJ-3461
// Memory Limit: 65 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize(3)//O3
//#pragma GCC optimize(2)//O2
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define base 233
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
//#define int long long
//#define double long double
//#define rep(i,x,y) for(register int i = x; i <= y;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-
优化文本排序实现模式串t的最大匹配

本文介绍了一种使用KMP算法优化字符串排序的方法,目的是在给定的文本串s中找到尽可能多的出现模式串t。通过构造和匹配过程,确保字符'0'和'1'的对应关系,最后输出排序后的s。
最低0.47元/天 解锁文章
754

被折叠的 条评论
为什么被折叠?



