这个问题涉及到字符串处理+搜索优化
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef set<int>::iterator ssii;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
pair<int, int> crack(int n) {
int st = sqrt(n);
int fac = n / st;
while (n % st) {
st += 1;
fac = n / st;
}
return make_pair(st, fac);
}
inline ll qpow(ll a, int n) {
ll ans = 1;
for(; n; n >>= 1) {
if(n & 1) ans *= 1ll * a;
a *= a;
}
return ans;
}
template <class T>
inline bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll ksc(ll a, ll b, ll mod) {
ll ans = 0;
for(; b; b >>= 1) {
if (b & 1) ans = (ans + a) % mod;
a = (a * 2) % mod;
}
return ans;
}
ll ksm(ll a, ll b, ll mod) {
ll ans = 1 % mod;
a %= mod;
for(; b; b >>= 1) {
if (b & 1) ans = ksc(ans, a, mod);
a = ksc(a, a, mod);
}
return ans;
}
template <class T>
inline bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
bool _check(int x) {
//
return true;
}
int bsearch1(int l, int r) {
while (l < r) {
int mid = (l + r) >> 1;
if(_check(mid)) r = mid;
else l = mid + 1;
}
return l;
}
int bsearch2(int l, int r) {
while (l < r) {
int mid = (l + r + 1) >> 1;
if(_check(mid)) l = mid;
else r = mid - 1;
}
return l;
}
template<class T>
bool lexSmaller(vector<T> a, vector<T> b) {
int n = a.size(), m = b.size();
int i;
for(i = 0; i < n && i < m; i++) {
if (a[i] < b[i]) return true;
else if (b[i] < a[i]) return false;
}
return (i == n && i < m);
}
// ============================================================== //
const int maxn = 5, slen = 500;
char str[slen];
int lim[maxn], n, LEN;
int tlen[maxn], l[maxn], sub[maxn][maxn];
int st[maxn];
bool check() {
int vis[maxn];
memset(vis, 0, sizeof(vis));
vis[n-1] = 1, st[n-1] = 0;
for (int i = n-1; i >= 1; i--) {
int p = st[i];
// p follow the substring of string i
for (int j = 0; j < l[i]; j++) {
int id = sub[i][j];
if (id == -1) p++;
else {
if (!vis[id]) { vis[id] = true; st[id] = p; }
else {
for (int d = 0; d < tlen[id]; d++) {
if (str[p+d] != str[ st[id]+d ]) return false;
}
}
p += tlen[id];
}
}
}
return true;
}
bool h(int cur, int maxll) {
int t = maxll;
for (int i = cur; i < n; i++) t *= lim[i];
if (t < LEN) return false;
return true;
}
bool dfs(int cur, int len, int k, int maxll) {
if (h(cur, maxll) == false) return false;
if (cur == n) {
// check valid
return tlen[n-1] == LEN && check();
}
if (k && k == l[cur]) {
// substr cur is finished, get tlen
tlen[cur] = 0;
for (int i = 0; i < l[cur]; i++) {
int id = sub[cur][i];
tlen[cur] += (id == -1 ? 1 : tlen[id]);
}
return dfs(cur+1, 0, 0, max(maxll, tlen[cur]));
}
if (len == 0) {
// enumerate length of substr cur
for (int i = lim[cur]; i >= 1; i--) {
l[cur] = i;
if (dfs(cur, i, 0, maxll)) return true;
}
}
else {
// enumerate sub(cur, k)
for (int i = cur-1; i >= -1; i--) {
sub[cur][k] = i;
if (dfs(cur, len, k+1, maxll)) return true;
}
}
return false;
}
void init() {
memset(tlen, 0, sizeof(tlen));
memset(l, 0, sizeof(l));
memset(sub, 0, sizeof(sub));
memset(st, 0, sizeof(st));
}
int main() {
freopen("input.txt", "r", stdin);
while (scanf("%d", &n) != EOF) {
init();
// get data
for (int i = n-1; i >= 0; i--) scanf("%d", &lim[i]);
scanf("%s", str);
LEN = strlen(str);
reverse(str, str + LEN);
// then dfs
int ans = dfs(0, 0, 0, 1);
if (ans) printf("Yes\n");
else printf("No\n");
}
}
大佬是用什么软件做出这个图的呀
macbook 的 keynote
是不是也感觉他做的显示效果很好~黑红分明,名词加粗还有图
是啊是啊