zoukankan      html  css  js  c++  java
  • poj 2229 Sumsets

      从n=1开始写,写到十三十四就比较好发现规律了:

      1、当n为偶数的时候; 将所有带有1的数列罗列出来,他们是a[n-1]的所有数列+1之后的数列;将所有没带有2的数列罗列出来,则它们正好都是a[n/2]的所有数列乘以2之后的数列;  因此,得出:a[n]=a[n-1]+a[n/2];

      2、当n为奇数时, a[n]=a[n-1]  这个显而易见的了。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <cstdlib>
     7 #include <cctype>
     8 #include <queue>
     9 #include <stack>
    10 #include <map>
    11 #include <vector>
    12 #include <set>
    13 #include <utility>
    14 #define ll long long
    15 #define inf 0x3f3f3f3f
    16 #define mod 1000000000
    17 using namespace std;
    18 
    19 int a[1000005];
    20 void get_table()
    21 {
    22     a[1]=1,a[2]=a[3]=2,a[4]=a[5]=4;
    23     for(int i=6;i<=1000000;i++)
    24     {
    25         if(i&1)
    26             a[i]=a[i-1];
    27         else
    28             a[i]=(a[i-1]+a[i>>1])%mod;
    29     }
    30 }
    31 int main()
    32 {
    33     //freopen("input.txt","r",stdin);
    34     get_table();
    35     int n;
    36     scanf("%d",&n);
    37     printf("%d
    ",a[n]);
    38     return 0;
    39 }
  • 相关阅读:
    Android Training
    Android Training
    简述Activity与Window关系
    简述Activity生命周期
    Python基础之元组及range
    python基础数据类型之列表
    python之字符串
    python基础之int整型
    python基础知识之格式化
    Python基础知识初识 (二)
  • 原文地址:https://www.cnblogs.com/geek1116/p/5673533.html
Copyright © 2011-2022 走看看