您的位置:首页 > 其它

序列(数组简化递归时间复杂度)

2017-03-25 20:14 295 查看

序列

Time Limit: 1000MS
Memory Limit: 65536KB
Submit

Statistic

Problem Description
import java.util.Scanner;
import java.util.Arrays;
import java.math.*;
public class Main{
static int a[] = new int[1100];
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
while(input.hasNextInt())
{
int n = input.nextInt();
System.out.println(f(n)+1);
}
}
public static int f(int n)
{
int sum = 0;
if(n==1)
return 0;
else
{
for(int i=n/2;i>=1;i--)
{
if(a[i]!=0)
sum+= a[i]+1;
else
{
a[i]=f(i);
sum+=a[i]+1;
}

}

}
return sum;

}
}


我们来定义这样一种序列,这个序列的第一个数字是n,并且数列中的每一项必须大于等于下一项的二倍(如果存在下一项)。我们想知道满足条件的合法序列有多少个?
比如n = 6
6
6 3
6 2
6 1
6 3 1
6 2 1
一共有6个合法的。

Input

多组输入。
输入数据的第一行包含数字n(1<=n<=1000)。

Output

输出所求的结果。

Example Input

6


Example Output

6


Hint

Author

cz
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐