Los calculate the number of Valley P1028- * [recursive]

Meaning of the questions:

We asked to find the number (n comprises a natural number entered) having the following number of properties:

Start with a natural number n (n≤1000), then this processing natural number as follows:

Without any treatment;

In its left plus a natural number, but the number of natural numbers can not exceed half of the original;

After adding a few, this rule continues the process until it can not be together until the natural numbers.

Input format
a natural number n (n≤1000)

Output format of
an integer, having the number indicates the number of properties.

Sample Input Output
Input # 1 replication
6
Output # 1 replication
6
Description / Tips
satisfying the condition number
6,16,26,126,36,136

answer:

Recursive, a [n] = a [1] + a [2] + ... + a [n / 2], starting from 1 has been pushed to n / 2

Code:

#include<stdio.h>
int main()
{
	int n,a[1005];
	scanf("%d",&n);
	for(int i=0;i<=n;i++)a[i]=1;
	for(int i=1;i<=n;i++)for(int j=1;j<=i/2;j++)a[i]+=a[j];
	printf("%d\n",a[n]);
}
Released eight original articles · won praise 1 · views 314

Guess you like

Origin blog.csdn.net/weixin_42921101/article/details/104310056