Jesus Is Here [recurrence] 2015 Shenyang online

Topic Link https://nanti.jisuanke.com/t/41175

  Since Baidu Star preliminaries to do it on a table to find themselves playing a regular title, this expansion makes me feel almost insane, and today this question I Siding dead two or three hours simply did not see any law, I was too tender a point - and this is my first time doing recurrence of problems, questions still to be for high-ah!

  If the relative ideas (big brother looked wonderful parse https://blog.csdn.net/chenzhenyu123456/article/details/48579695 ), this question can be solved

  First need to open a structure variable to store different elements 1.'c 'number 3. 2. string length corresponding to all the strings' targets and 4. element values' location C, slightly Thinking you can get the following relationship:

  1.'c 'number: a2.num = a0.num + a1.num

  2. The length of the string: a2.len = a0.len + a1.len

  3. The location of all 'c' corresponding to the target string and: a2.sum = a0.num + a1.num + a0.len * a1.num

  4. element value: a2.val = a0.val + a1.val + (a1.sum + a0.len * a1.num) * a0.num-a1.num * a0.sum

  Ps: remainder part needs special attention, it is easy to make mistakes.

  Refer to code:

  

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 const long long aha=530600414;
 5 struct ha{
 6     long long len,sum,val,num;
 7     ha(){}
 8     ha(long long x,long long y,long long z,long long p):len(x),sum(y),val(z),num(p){}
 9 };
10 int t,n;
11 int main(){
12     scanf("%d",&t);
13     for(int Case=1;Case<=t;Case++){
14         scanf("%d",&n);
15         ha a0(1,1,0,1),a1(2,0,0,0),a2;
16         n-=2;
17         while(n--){
18             a2=ha((a0.len+a1.len)%aha,
19                  ((+ a0.sum a1.sum) Aha% + * a0.len a1.num Aha%)% Aha,
 20                  (((+ a0.val a1.val) Aha% + (+ a1.sum a0.len * a1.num)% * Aha Aha a0.num%)% * Aha-a1.num a0.sum% + Aha Aha)% Aha,
 21                  (a0.num a1.num +)% Aha);
22              a0 = a1;
23              a1 = A2;
24              // printf ( "% = their LLD, sum =% LLD, Val =% LLD, LLD num =% \ n", a2.len, a2.sum, a2.val, a2.num); 
25          }
 26          printf ( " Case #% d:% LLD \ n " , Case, a2.val);
27      }
 28      return  0 ;
29 }

 

  

Guess you like

Origin www.cnblogs.com/xxmlala-fff/p/xxmlala-JesusIsHere.html