码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ 2872 Binary Partitions

时间:2015-09-02 21:56:47      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

先写一个完全背包,然后找规律,然后打表。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int a[2000000 + 100];
int Zhong[2000000 + 100];
int tot;
int MOD = 1000000;

int main()
{
    a[0] = 1;
    a[1] = 1;
    a[2] = 2;
    a[3] = 2;
    int i = 4;
    tot = 0;
    int k = 0;
    Zhong[tot] = 2;
    while (1)
    {
        if (i > 2000000) break;
        a[i] = (a[i - 1] + Zhong[k]) % MOD;
        a[i + 1] = (a[i - 1] + Zhong[k]) % MOD;
        tot++; Zhong[tot] = a[i + 1] % MOD;
        a[i + 2] = (a[i + 1] + Zhong[k]) % MOD;
        a[i + 3] = (a[i + 1] + Zhong[k]) % MOD;
        tot++; Zhong[tot] = a[i + 3] % MOD;
        k++;
        i = i + 4;
    }
    int n;
    int T;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        printf("%d\n", a[n] % MOD);
    }
    return 0;
}

 

ZOJ 2872 Binary Partitions

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/4779470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!