博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
题目1084:整数拆分 (递推)
阅读量:7040 次
发布时间:2019-06-28

本文共 763 字,大约阅读时间需要 2 分钟。

题意:

问一个数拆分成2的幂的和的方法数有多少种。

 

我是先通过找列举前面的找规律

n   种数

1    1

2    2

3    2

4    4

5    4

6    6

7    6

8    10

9    10

10   14

……

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 12 using namespace std;13 14 typedef long long ll;15 16 const int mod = 1000000000;17 int f[1000010];18 19 void init()20 {21 f[1] = 1;22 for(int i=2;i<=1000000;i++)23 {24 if(i&1) f[i] = f[i-1]%mod;25 else f[i] = (f[i-1]+f[i/2])%mod;26 }27 }28 29 int main()30 {31 int n;32 init();33 while(~scanf("%d",&n))34 {35 printf("%d\n",f[n]);36 }37 return 0;38 }
View Code

 

转载于:https://www.cnblogs.com/hadis-yuki/p/4393759.html

你可能感兴趣的文章
无损音乐资源
查看>>
Foxmail配置IMAP账号
查看>>
linux下查看一个进程的启动时间和运行时间
查看>>
网页常用js代码汇集
查看>>
【HM】第9课:Cookie与HttpSession详解
查看>>
NEC面部识别系统助力台北世界大学生运动会
查看>>
nfs
查看>>
UltraEdit实现“删除包含某个关键字的所有行”
查看>>
WSFC 维护模式操作粒度控制
查看>>
linux kill 命令
查看>>
为什么使用useLegacyV2RuntimeActivationPolicy?
查看>>
Shell工作笔记01
查看>>
windows 2008 R2搭建简单WEB服务器
查看>>
hyper-v故障转移群集之4、创建群集
查看>>
webpack命令行
查看>>
多网卡的7种bond模式原理
查看>>
用update和replace在sql中替换某一个字段的部分内容
查看>>
Web框架原理
查看>>
HEX解码
查看>>
.pyc是什么鬼?
查看>>