[Inscription] sequence count - Bridge Cup Blue

Title: sequence count

[Problems] Description
Bob would like to know the number of sequence of positive integers satisfying the following conditions:
1. The first term is n-;
2. not more than the second n-;
3. the third from the start, each smaller than the first two the absolute value of the difference.
Calculate, for a given n, how many sequences satisfy the conditions.


[Input format
input line contains an integer n.
[] Output format
output an integer that represents the answer. The answer may be large, please answer output is divided by 10,000.


Sample input] [
4
[output] Sample
7
[Example Description]
The following is the sequence satisfy the condition:
4. 1
4. 1. 1
4. 1 2
4 2
4 2. 1
4. 3
4 4
[evaluation scale use cases and conventions]
for 20 % reviews use cases, 1 <= n <= 5 ;
for 50% of the evaluation use cases, 1 <= n <= 10 ;
for 80% of the evaluation use cases, 1 <= n <= 100 ;
for all reviews use cases, 1 < = n <= 1000.


Ideas: Memory of recursive

The third topic can be drawn from the recursive formula:

  f (old, now) it is meant an element of a previous old, now the sum of the current sequence elements.

  f(old,now) = f(now, 1) + .... + f(now,|old-now|-1) + 1;

  

  This leads us to the condition in accordance with 2,3: the sum of the sequence f (old, now) a = 1 + f (old, now -1) + f (now, | old - now | - 1);

 

It follows that the code (c):

  

#include <stdio.h> 
#include <math.h>
 int HX [ 1001 ] [ 1001 ] = { 0 }; 

Long  Long  int DFS ( int Old, int now) { 
IF (now <= 0 ) return 0 ; IF (HX [Old] [now] =! 0 ) return HX [Old] [now]; // an absolute value of difference is smaller than each of the first two from the third start, i.e., from 1 to fabs (old-now ) -1 // a sequence and the beginning of the old now, a total of: own + now <old + third start of qualifying HX [old] [now] = ( . 1 + DFS (old, NOW- . 1) + DFS (now, FABS (Old-now) - . 1 ))% 10000 ; return HX [Old] [now]; } int main () { int NUM; Scanf ( " % D " , & NUM); the printf ( " % I64d " , DFS (NUM, NUM)); return 0 ; } // from the third start, in line with the recursive formula: // F (Old, now) = F (now,. 1) + .... + F (now, | now-old | -1) + 1; // ★ 1 from the absolute value of the old and now with their own -1

 

2020-03-25-20:57:01

 

  

 

Guess you like

Origin www.cnblogs.com/Sxccz/p/LanQiao_9.html
Recommended