HDOJ_2709_Sumsets

AC代码:

#include <iostream>
#include <cstdio>
#define Max 1000005
using namespace std;

long long int a[Max];

void hanshu()
{
    a[1]=1;a[2]=2;
    for(long long int j=3;j<=1000001;j++)
    {
        if(j%2==1)
            a[j]=a[j-1];
        else
            a[j]=(a[j/2] + a[j-2])%1000000000;
    }
        
}


int main(void)
{
    freopen("in.txt","r",stdin);
    hanshu();
    long long int N;
    while(scanf("%lld",&N)!=EOF)
    {
        printf("%lld
",a[N]);
    }
    
    fclose(stdin);
    return 0;
}
原文地址:https://www.cnblogs.com/phaLQ/p/9941436.html