HDU 3336 next array count prefix count

Source: Internet
Author: User

Total prefix COUNT = number of prefix categories + number of occurrences of each prefix after

A good question is posted, but the question is not very clear. That's why next [J] + 1 = next [J + 1] is not counted?

Http://972169909-qq-com.iteye.com/blog/1114968

If next is equal to the next value plus one, this statistics will be calculated later, so ignore

# Include <stdio. h> # include <string. h> # define Val 200005int next [Val], lenp; char P [Val]; void set_next (); int main () {int cas, I, ans; for (scanf ("% d", & CAS); CAS --) {scanf ("% d", & lenp); scanf ("% s", P ); set_next (); ans = lenp + next [lenp]; for (I = lenp-1; I> = 1; I --) if (next [I]! = Next [I + 1]-1) ans + = next [I]; printf ("% d \ n", ANS % 10007);} return 0 ;} void set_next () {int K, J; k =-1, j = 0; next [J] = K; while (j <lenp) {If (k =-1 | P [J] = P [k]) {k ++; j ++; next [J] = K ;} else K = next [k] ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.