The number of Java implementation of the Blue Bridge Cup simulate the sequence of positive integers

Problem description
  small quantities that would like to know, positive integers satisfying the following conditions sequence:
  1. First term is n-;
  2. not more than the second n-;
  3. the third from the start, each smaller than a difference of the first two the absolute values.
  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.
Input Sample
4
Sample Output
7
Example Description
  The following is a sequence satisfying the condition:
  4 1
  4 1 1
  4 2 1
  4 2
  4 1 2
  4. 3
  4 4
Evaluation and convention scale use cases
  for evaluation by 20% in Example, 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 .

package 第十三次模拟;

import java.util.Scanner;

public class Demo8序列 {
	public static int n=0,count=0;
	public static int [] []map ;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 n =sc.nextInt();
		 sc.close();
		 map = new int [n+1][n+1];
		 for (int i = 1; i <=n; i++) {
			map[i][i]=1;
			map[i][0]=1;
			map[0][i]=1;
		}
		 for (int i = 1; i <=n; i++) {
			count+=f(n,i);
//			System.out.println(count);
		}
		 System.out.println(count);
//		 System.out.println(f(4,2));
		 
	}
	public static int f(int x,int y){
		if(map[x][y]!=0){
			return map[x][y];
		}
		for (int i = Math.abs(x-y)-1; i>=0; i--) {
			map[x][y]+=f(y,i);
		}
		map[y][x]=map[x][y];
		return map[x][y];
	}

}

Released 1471 original articles · won praise 10000 + · views 1.76 million +

Guess you like

Origin blog.csdn.net/a1439775520/article/details/104750318