Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7:

1) 1+1+1+1+1+1+1 
2) 1+1+1+1+1+2 
3) 1+1+1+2+2 
4) 1+1+1+4 
5) 1+2+2+2 
6) 1+2+4

Help FJ count all possible representations for a given integer N (1 <= N <= 1,000,000).

Input

A single line with a single integer, N.

Output

The number of ways to represent N as the indicated sum. Due to the potential huge size of this number, print only last 9 digits (in base 10 representation).

Sample Input

7

Sample Output

6

当 i 为奇数时可以将 i-1 的展开项加 1 得到 i 的展开项
当 i 为偶数是单纯的将 i-1 的展开项加 1 无法得到所有的 i 的展开项,因为 i 是偶数,所以 i 的展开项中有全为偶数的情况
将全为偶数的展开像除以 2 得到的是 i/2 的展开项(可以倒着想,将 i/2 的展开项乘 2 得到 i 的全偶数展开项) 转移式为 dp[i] = (i&1)?(dp[i-1]):(dp[i-1]+dp[i/2])
 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = 1e6+;
int dp[maxn]; int main(){
int n;
scanf("%d",&n);
memset(dp,,sizeof(dp));
dp[] = ; for(int i=;i<=n;++i){
if(i&)
dp[i] = dp[i-];
else{
dp[i] = dp[i-] + dp[i>>];
if(dp[i]>)
dp[i] -= ;
}
} printf("%d\n",dp[n]);
return ;
}

最新文章

  1. 在Salesforce中向外公布Service去创建Lead,并且用Asp.Net去调用此Service
  2. hdu 5929 Basic Data Structure
  3. 【POJ 1698】Alice&#39;s Chance(二分图多重匹配)
  4. 关于MVC
  5. Codeforces Round #204 (Div. 2)-&gt;B. Jeff and Periods
  6. How to install ffmpeg,mp4box,mplayer,mencoder,flvtool2,ffmpeg-php on centos
  7. [开源夏令营][四] Docker remote API 之 镜像篇
  8. [SinGuLaRiTy] ZKW线段树
  9. Java post提交表单限制
  10. cmd命令行进入DOS方式编译运行C语言程序实现字符串转换
  11. ActiveMQ_Windows版本的安装部署
  12. 第三十篇-ToolBar的使用
  13. IDAPython学习(二)
  14. 组件的三大属性state,props,refs与事件处理
  15. ModuleNotFoundError No module named urllib2
  16. MySQL报错】ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 43, found 39.
  17. Android Build.VERSION.SDK_INT兼容介绍
  18. shred_linux_unix
  19. 普通用户开通sudo权限:xxx is not in the sudoers file.This incident will be reported.的解决方法
  20. Java CST格式字符串转换成Date类型的数据

热门文章

  1. 外部的 JavaScript
  2. iOS 语言国际化配置
  3. 【杂题总汇】HDU-5215 Cycle
  4. Vmware+CentOs7+共享目录
  5. Co. - Microsoft - Windows - Tomcat、JDK、MySQL通过 Inno 集成为exe部署包
  6. Zabbix源码安装部署
  7. html5 手风琴菜单
  8. JS高级. 02 面向对象、创建对象、构造函数、自定义构造函数、原型
  9. 使用百度定位Api获取当前用户登录地址
  10. Angular : 基础语句说明, 响应式表单指令, 组件生命周期钩子