HDU 5459 Jesus is here (recursive)

Source: Internet
Author: User
Tags define local

A bit of a hassle of recursion, look at the time please be patient, recursion when not nested, to small problems in the direction of decomposition, and then pay attention to the boundary.

The recursive character of the string is

Define f as the total length in SI

First you can get

Then consider the combination between Si-2 and Si-1.

In order to get a small problem, split

In order to express the convenience and the logical clarity, define the total length of the si~si between

Because there's a Si-3 in the middle of the si-2 and si-2.

Therefore, the total length of the combination can be expressed as

CI indicates the number of occurrences of CFF in Si, and Li indicates the length of Si

Define a function CCL

And then there's a part of Si-2 and Si-3.

Defined

At this point, the overall plan can be expressed

And then gradually refine it from the top down

Consider the calculation of G (i)

There's a recursion in there, first you get

To make it easier to define a function again

Obviously, this is much easier to calculate.

The rest of the combination can also be expressed.

Last part F12 (i)

#include <bits/stdc++.h>using namespacestd;#definePB push_back#defineMP Make_pair#defineFi first#defineSe SecondtypedefLong Longll;Const intN =201314+5ll F[n], C[n], l[n], g[n];Const intMod =530600414; inline ll F21 (inti) {returnf[i]-f[i-2]-f[i-1]; }inline ll CCL (intIintJintK) {returnc[i]*c[j]%mod*l[k];} Inline ll F12 (inti) {returng[i-2]+F21 (I-1) +CCL (I-3, I-2, I-2); }//Use the i-3 .//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifl[1] =1; l[2] =2; l[3] =3; l[4] =5; c[3] =1; c[4] =1; g[3] =3; g[4] =5;  for(inti =5; I <=201314; i++) {L[i]= (l[i-1]+l[i-2])%Mod; C[i]= (c[i-1]+c[i-2])%Mod; F[i]= (f[i-1]+f[i-2]+g[i-2]+CCL (I-2, I-2, I-3) +f12 (I-1) +mod)%mod;//used to i-4, so starting from 5G[i] = (g[i-1]+g[i-2]+CCL (I-1, I-1, I-2) +CCL (I-2, I-2, I-1) +f12 (i) +f21 (i) +CCL (i)2, I-1, i))%mod;//F[i] and l[i], so f[i]l[i] in front    }    intT, Kas =0; scanf"%d",&T);  while(t--){        intN scanf"%d",&N); printf ("Case #%d:%i64d\n",++Kas,f[n]); }    return 0;}

HDU 5459 Jesus is here (recursive)

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.