Spoon Devil Love Arithmetic

来源:互联网 发布:云南广电网络oa 编辑:程序博客网 时间:2024/04/19 11:42
Spoon Devil Love Arithmetic

Time Limit:1s Memory Limit:32MByte

Submissions:66Solved:19

DESCRIPTION
Spoon Devil want to use some integers which are power of 2 to sum to a number NN. But he find that there are many possible representations.For example, given 7 as NN:7 = 1+1+1+1+1+1+17 = 1+1+1+1+1+27 = 1+1+1+2+27 = 1+1+1+47 = 1+2+2+27 = 1+2+4Please tell Spoon Devil how many possible representations there are for a given number N (1N1,000,000)N (1≤N≤1,000,000).
INPUT
The first line is a single integer TT which is the number of test cases.And for each test case, only a integer NN.
OUTPUT
For each test case, output a line with the answer mod 1000000000.
SAMPLE INPUT
17
SAMPLE OUTPUT
6
动态规划,奇数时a[i]等于a[i-1]的次数和a[i/2]乘于2的次数和
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const int N = 1001111;int a[N];const int mod=1000000000;int main(){    memset(a,0,sizeof(a));    a[1]=1,a[2]=2,a[3]=2,a[4]=4,a[5]=4;    for(int i=6;i<=N;i++)    {        if(i%2==0)        {            a[i]=(a[i-1]+a[i/2])%mod;        }        else        {            a[i]=a[i-1];        }    }    int n, t;    scanf("%d", &t);    while(t--)    {        scanf("%d",&n);        printf("%d\n",a[n]%mod);    }    return 0;}

0 0