Sumsets

Time Limit : 6000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 45   Accepted Submission(s) : 20

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

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
题意 给定一个n,n又2的幂次方相加得到,问有多少中相加的方式
分析 当n为奇数的时候 就是再前一个的基础上加上1,a[n]=a[n-1]
  当n为偶数的时候:
    如果加数里含有1,则一定至少有2个1,就是对n-2后面+1+1,就是a[n-2]
    如果加数里面没有1,即对n/2的每一个加数乘以2,总类数为a[n/2]
  所以n为偶数时的总类数为a[n]=a[n-2]+a[n/2]
 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
int a[+];
int main()
{
int n;
a[]=,a[]=;
for(int i=;i<=;i++)
{
if(i%)
{
a[i]=a[i-];
}
else
{
a[i]=a[i-]+a[i/];
a[i]%=;
}
}
while(~scanf("%d",&n))
{
printf("%d\n",a[n]);
}
return ;
}

最新文章

  1. android support的作用及其常见错误的解决
  2. 关于netstat
  3. PostgreSQL和Greenplum、Npgsql
  4. sql server还原数据库文件(.bak)常见问题解决办法笔记
  5. RFID Hacking②:PM3入门指南
  6. java nio管道
  7. linux命令-shopt
  8. C# 数据结构 栈 Stack
  9. CentOS 7 源码编译安装 Mysql 5.7
  10. ActiveXObject函数详解(转自http://eyesinthesky.iteye.com/blog/1560033)
  11. git删除掉已经保存的用户名密码
  12. 023合并K个链表并排序
  13. 将现有项目添加到TFS中
  14. mybatis 转义
  15. spring(aop面向切面编程)
  16. 史上最坑 idea 更改代码不生效
  17. JVM调优命令-jinfo
  18. C++ 字符串的编码
  19. Java——IO类,字符流写数据
  20. Parallel学习

热门文章

  1. 解决 Database Configuration Assistannt安装oracle实例使的 警告
  2. Android学习笔记_46_fragment的简单应用
  3. Android学习笔记_24_多媒体MediaPlayer对象之音乐播放器与SoundPool声音池
  4. 使用带有对象的data-ng-bind
  5. centos 安装配置 rabbitmq 以及nginx转发
  6. Centos6.9 安装Oracle11gR2
  7. JavaScript 基础(四) 循环
  8. 『ACM C++』PTA浙大 | 基础题 - 打印沙漏
  9. window/linux下获取文件MD5
  10. oracle优化-leading提示和ordered提示以及materialize提示