当前位置: 首页 > news >正文

国外建站系统/淘宝seo优化是什么

国外建站系统,淘宝seo优化是什么,网站设计的建设目的,wordpress透明菜单题意:给定只有ab的字符串,求其中不连续非空回文子序列的个数。 解:用所有回文子序列减去回文子串。 容易想到枚举中线。 设f[i]表示以i为中线,回文字符的个数。那么回文子序列就是∑(2f[i] - 1) 怎么求f[i]呢?卷积&…

题意:给定只有ab的字符串,求其中不连续非空回文子序列的个数。

解:用所有回文子序列减去回文子串。

容易想到枚举中线。

设f[i]表示以i为中线,回文字符的个数。那么回文子序列就是∑(2f[i] - 1)

怎么求f[i]呢?卷积!

我们考虑把i变成中线 * 2,那么f[i] = ( ∑(s[j] == s[i - j])  + 1) / 2

令a = 1,b = 0,那么卷积得出的就是所有a的回文字符数。同理可以求得所有b的回文字符数。

然后用回文自动机求一遍回文子串的数目,相减即可。

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <algorithm>
  4 #include <cmath>
  5 
  6 typedef long long LL;
  7 const int N = 100010;
  8 const LL MO = 1e9 + 7;
  9 const double pi = 3.1415926535897932384626;
 10 
 11 struct cp {
 12     double x, y;
 13     cp(double X = 0, double Y = 0) {
 14         x = X;
 15         y = Y;
 16     }
 17     inline cp operator +(const cp &w) const {
 18         return cp(x + w.x, y + w.y);
 19     }
 20     inline cp operator -(const cp &w) const {
 21         return cp(x - w.x, y - w.y);
 22     }
 23     inline cp operator *(const cp &w) const {
 24         return cp(x * w.x - y * w.y, x * w.y + y * w.x);
 25     }
 26 }a[N << 2];
 27 
 28 int r[N << 2], f[N << 1];
 29 char s[N];
 30 
 31 inline LL qpow(LL a, int b) {
 32     LL ans = 1;
 33     while(b) {
 34         if(b & 1) {
 35             ans = ans * a % MO;
 36         }
 37         a = a * a % MO;
 38         b = b >> 1;
 39     }
 40     return ans;
 41 }
 42 
 43 inline void FFT(int n, cp *a, int f) {
 44     for(int i = 0; i < n; i++) {
 45         if(i < r[i]) {
 46             std::swap(a[i], a[r[i]]);
 47         }
 48     }
 49 
 50     for(int len = 1; len < n; len <<= 1) {
 51         cp Wn(cos(pi / len), f * sin(pi / len));
 52         for(int i = 0; i < n; i += (len << 1)) {
 53             cp w(1, 0);
 54             for(int j = 0; j < len; j++) {
 55                 cp t = a[i + len + j] * w;
 56                 a[i + len + j] = a[i + j] - t;
 57                 a[i + j] = a[i + j] + t;
 58                 w = w * Wn;
 59             }
 60         }
 61     }
 62 
 63     if(f == -1) {
 64         for(int i = 0; i <= n; i++) {
 65             a[i].x /= n;
 66         }
 67     }
 68     return;
 69 }
 70 
 71 namespace pam {
 72     int tr[N][26], fail[N], cnt[N], len[N], last, tot;
 73     inline void init() {
 74         len[1] = -1;
 75         fail[0] = fail[1] = 1;
 76         tot = last = 1;
 77         return;
 78     }
 79     inline int getfail(int d, int x) {
 80         while(s[d - len[x] - 1] != s[d]) {
 81             x = fail[x];
 82         }
 83         return x;
 84     }
 85     inline void insert(int d) {
 86         int f = s[d] - 'a';
 87         int p = getfail(d, last);
 88         if(!tr[p][f]) {
 89             ++tot;
 90             len[tot] = len[p] + 2;
 91             fail[tot] = tr[getfail(d, fail[p])][f];
 92             tr[p][f] = tot;
 93         }
 94         last = tr[p][f];
 95         cnt[last]++;
 96         return;
 97     }
 98     inline LL count() {
 99         LL ans = 0;
100         for(int i = tot; i >= 2; i--) {
101             ans = (ans + cnt[i]) % MO;
102             (cnt[fail[i]] += cnt[i]) %= MO;
103         }
104         return ans;
105     }
106 }
107 
108 int main() {
109     scanf("%s", s);
110     int n = strlen(s) - 1;
111     for(int i = 0; i <= n; i++) {
112         a[i].x = (s[i] == 'a');
113     }
114     int len = 2, lm = 1;
115     while(len <= n + n) {
116         len <<= 1;
117         lm++;
118     }
119     for(int i = 1; i <= len; i++) {
120         r[i] = (r[i >> 1] >> 1) | ((i & 1) << (lm - 1));
121     }
122 
123     FFT(len, a, 1);
124     for(int i = 0; i <= len; i++) {
125         a[i] = a[i] * a[i];
126     }
127     FFT(len, a, -1);
128     for(int i = 0; i <= n + n; i++) {
129         f[i] = ((int)(a[i].x + 0.5) + 1) >> 1;
130     }
131 
132     for(int i = 0; i <= n; i++) {
133         a[i].x = (s[i] == 'b');
134         a[i].y = 0;
135     }
136     for(int i = n + 1; i <= len; i++) {
137         a[i] = cp(0, 0);
138     }
139     FFT(len, a, 1);
140     for(int i = 0; i <= len; i++) {
141         a[i] = a[i] * a[i];
142     }
143     FFT(len, a, -1);
144     for(int i = 0; i <= n + n; i++) {
145         f[i] += ((int)(a[i].x + 0.5) + 1) >> 1;
146     }
147 
148     LL ans = 0;
149     for(int i = 0; i <= n + n; i++) {
150         ans = (ans + qpow(2ll, f[i]) - 1) % MO;
151     }
152     pam::init();
153     for(int i = 0; i <= n; i++) {
154         pam::insert(i);
155     }
156     ans = (ans - pam::count() + MO) % MO;
157     printf("%lld", ans);
158     return 0;
159 }
AC代码

 

转载于:https://www.cnblogs.com/huyufeifei/p/10246506.html

http://www.lbrq.cn/news/755911.html

相关文章:

  • 怎么查网站备案接入商/武汉全网推广
  • 如何做自己网站的seo/精准引流推广团队
  • 我的世界做图的网站/百度公司的业务范围
  • 邢台网站建设服务商/seo点击软件
  • 东莞企业高端网站建设/百度新闻下载安装
  • 做阿里巴巴类似的网站/2022最新小学生新闻
  • 龙岩网站制作教程/湖南seo推广多少钱
  • 苏州网站建设公司找哪家/优化营商环境评价
  • 百度推广网站怎么做/汽车营销活动策划方案
  • 南京网站设计价格/现在推广什么app最挣钱
  • 广东华业建设有限公司网站/怎样把个人介绍放到百度
  • 网站建设电话销售话术模板大全/口碑营销方案
  • 河南专业网站建设公司/网站推广哪个平台最好
  • 重庆建站模板厂家/营销推广seo
  • 电商网站怎么做支付/企业线上培训平台
  • 58同城怎么做网站/seo任务
  • 网站不备案可以做淘宝客吗/百度排行
  • 首页制作教程/台州seo
  • 东莞做网站建设/营销策略都有哪些
  • 域名空间网站/网站访问量查询工具
  • 做网站v赚钱/巨量算数
  • dedecms怎么制作网站/湘潭seo优化
  • 在线写作网站/推广引流软件
  • 做导航网站有发展吗/搜索引擎优化需要多少钱
  • 一手房哪个网站做信息效果好/本站3天更换一次域名yw
  • 张家界网站制作与代运营/线上营销怎么做
  • asp.net jsp 网站开发/seo外链发布平台
  • 网站怎么设计好看/图片识别 在线识图
  • 设计新闻发布网站模板/东莞网络推广
  • 宁波城乡住房建设局网站/百度助手app免费下载
  • 实例分割-动手学计算机视觉13
  • 谷歌手机刷机和面具ROOT保姆级别教程
  • ​Visual Studio 2013.5 ULTIMATE 中文版怎么安装?iso镜像详细步骤
  • WEB安全--Java安全--Servlet内存马
  • C++第二十课:快递运费计算器 / 黑白配+石头剪刀布小游戏
  • 稳定且高效:GSPO如何革新大型语言模型的强化学习训练?