HYSBZ 2160 拉拉隊排練 回文自動機

2021-10-02 12:49:16 字數 931 閱讀 4459

題目大意:給出乙個字串 s ,和乙個整數 k,現在要求出所有長度為奇數的回文子串從大到小開始數前 k 個回文子串的長度的乘積 

題目分析:回文自動機跑一遍字串 s 後把長度為奇數的結點的長度和出現次數拿出來,配合上快速冪遍歷一遍求答案就好了

**:

#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int n=1e6+100;

const int mod=19930726;

char s[n];

int n;

struct palindrome_tree

void build()

int getfail(int x, int n)

void insert(char ch)

last = nxt[p][c]; // 當前節點成為上乙個節點

cnt[last]++; //當前節點回文串++

record[last] = n;

}void get_cnt()

}tree;

ll q_pow(ll a,ll b)

return ans;

}struct node

bool operator<(const node& a)const };

vectornode;

int main()

else

}if(k)

ans=-1;

printf("%lld\n",ans);

return 0;

}

HYSBZ 2160 拉拉隊排練 回文樹

題意 前k長的 奇數長度 的回文串 長度的乘積 題解 因為k很大,所以我們儲存,每個本質不同字串的長度和數量,然後排序,從大到小列舉一遍即可 include using namespace std const int n 1000010 typedef long long ll struct pt ...

HYSBZ 2160 拉拉隊排練(回文樹)

time limit 10 sec memory limit 259 mb submit 825 solved 324 submit status discuss 艾利斯頓商學院籃球隊要參加一年一度的市籃球比賽了。拉拉隊是籃球比賽的乙個看點,好的拉拉隊往往能幫助球隊增加士氣,贏得最終的比賽。所以作為...

BZOJ 2160 拉拉隊排練

time limit 10 sec memory limit 259 mb submit 832 solved 326 submit status discuss 艾利斯頓商學院籃球隊要參加一年一度的市籃球比賽了。拉拉隊是籃球比賽的乙個看點,好的拉拉隊往往能幫助球隊增加士氣,贏得最終的比賽。所以作為...