SDUT 序列

序列
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

我們來定義這樣一種序列,這個序列的第一個數字是n,並且數列中的每一項必須大於等於下一項的二倍(如果存在下一項)。我們想知道滿足條件的合法序列有多少個?
比如n = 6
6
6 3
6 2
6 1
6 3 1
6 2 1
一共有6個合法的。
Input

多組輸入。
輸入數據的第一行包含數字n(1<=n<=1000)。
Output

輸出所求的結果。
Sample Input

6
Sample Output

6
Hint

Source

cz

//import java.io.*;
//import java.math.*;
//import java.text.*;
//import java.math.BigInteger;
import java.util.*;
public class Main 
{
    static int[] a = new int[1232];
    static public int S(int m)
    {
        if(m==1)
            return 0;
        else 
        {
            int sum = 0;
            for(int i=m/2;i>=1;i--)
            {
                if(a[i]!=0)
                sum += a[i] + 1;
                else 
                {
                    a[i] = S(i);
                    sum += a[i] + 1;
                }
            }
            return sum;
        }
    }
    public static void main(String[] args)
    {
       Scanner cin = new Scanner(System.in);
       while(cin.hasNext())
       {
           int n = cin.nextInt();
           System.out.println(S(n)+1);
       }  
       cin.close();
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章