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用2^n之和的形式表示的方案数

思路:当N>1时,若N为奇数,则每个分解方案中至少含有一个1项。此时若每种分解方案中去掉一个1项,方案数不发生改变。

   即     N分解的方案数=(N-1)分解的方案数

   若该N为偶数,则分为两类情况:

   1、含有1项,同上,每个方案中去掉1项,方案数不变。

   2、不含有1项,此时每个方案中最小项应为2,若将每一项除2,方案数不变。

   即     N分解的方案数=(N-1)分解的方案数+(N/2)分解的方案数。

边界条件:当N=1时只有一种分解方案。

注意:可能溢出,需要取模


 #include<cstdio>
int s[];
int main()
{
int n; s[]=;
for( int i=; i<=; i++){
if( i%== )
s[i]=(s[i-]+s[i/])%;
else
s[i]=s[i-];
}
while(~scanf("%d",&n)){
printf("%d\n",s[n]);
} return ;
}

DP_Sumsets的更多相关文章

随机推荐

  1. 数据结构实验之数组二:稀疏矩阵(SDUT 3348)

    Problem Description 对于一个n*n的稀疏矩阵M(1 <= n <= 1000),采用三元组顺序表存储表示,查找从键盘输入的某个非零数据是否在稀疏矩阵中,如果存在则输出O ...

  2. Foundation-常用结构体

    复习 void test(){ struct Date{ int year; int month; int day; }; struct Date d={2015,5,14}; d.day=6; } ...

  3. sql mode 问题及解决 错误代码:1055 this is incompatible with sql_mode=only_full_group_by

    数据库升级到5.7.21后,一个正常的分组后按日期排序,并返回数据的语句开始报错: 语句如下: SELECT id,title,add_time FROM `message` GROUP BY add ...

  4. 简单的switch插件

    页面效果: 这个switch使用纯CSS实现,小巧简单 css代码 /* switch */ /* 开关样式 */ label.bui-switch-label .bui-switch { width ...

  5. nginx 配置简单 301 重定向

    server { listen ; server_name your.first.domain; rewrite ^(.*) http://your.second.domain:8000$1 perm ...

  6. Angular4.x+Ionic3 踩坑之路之打包时出现JAVASCRIPT HEAP OUT OF MEMORY的几种解决办法

    最近开发的一个比较大型的App时打生产环境包是出现内存不足导致打包失败的问题.然后百度发现解决方法都是一样,自己试了一下都没什么暖用,心里只想用呵呵来形容了.最后经朋友介绍,技术问题还得去谷歌,git ...

  7. 014-操作系统下验证下载文件的 MD5/SHA1/SHA256

    一.mac 1.md5 openssl md5 /path/to/file 新的macOS默认支持:md5 filename 2.sha256 openssl dgst -sha256 /path/t ...

  8. [C++/JavaScript]数据结构:栈和数列>案例引入(数制的转换)

    1 案例1:数制的转换 1.1 背景与原理 1.2 编程复现 (JavaScript版 复现) function convert(value, d){ stack = []; // 栈 result ...

  9. PyToune:一款类Keras的PyTorch框架

    PyToune is a Keras-like framework for PyTorch and handles much of the boilerplating code needed to t ...

  10. 小技巧 Mongodb 动态查询 除去 _class 条件

    最近在做通用模板标准示例项目,在使用  spring data jpa  Mongodb 的时候,动态查询会代入 _class条件. 为什么这么做其实也很好理解,写入数据库的数据中是有这个字段的.接受 ...