SDNU 1204. water problem (water issues)

Description

The total can be split into an integer and a power of 2, for example:
7=1+2+4
7=1+2+2+2
7=1+1+1+4
7=1+1+1+2+2
7=1+1+1+1+1+2
7=1+1+1+1+1+1+1
A total of six different splitting mode.
Another example: can be split into 4: 4 = 4,4 + 1 = 1 + 1 = 2 + 1,4 + 2,4 + 1 + 1 = 2.
Represents a number of n different split by f (n), for example, f (7) = 6.
It requires programming, reading n (no more than one million), the output f (n)% 1000000000.

Input

Each input comprises an integer: N (1 <= N <= 1000000).

Output

For each test, the output f (n)% 1000000000.

Sample Input

7

Sample Output

6

Hint

Water problem

Source

Unknown
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long

int n, f[1000000+8];

int main()
{
    f[0] = f[1] = 1;
    for(int i = 2; i<1000008; i++)
    {
        if(i%2)f[i] = f[i-1];
        else f[i] = (f[i-1]+f[i/2])%1000000000;
    }
    while(~scanf("%d", &n)  && n != 0)
    {
        printf("%d\n", f[n]);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/RootVount/p/10991032.html