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\n",a[n]);
38     return 0;
39 }
复制代码

 

posted @   爱喝可乐的咖啡  阅读(341)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示