...

 #include <iostream>
using namespace std;
int f[];
int n,i;
int main()
{
cin>>n;
f[]=;
for (i=;i<=n;i++)
{
f[i]=f[i-];
if (!(i&)) f[i]+=f[i/];
f[i]%=;
}
cout<<f[n];
return ;
}

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).

给出一个N(1≤N≤10^6),使用一些2的若干次幂的数相加来求之.问有多少种方法

Input

一个整数N.

Output

方法数.这个数可能很大,请输出其在十进制下的最后9位.

Sample Input

7

Sample Output

6

有以下六种方式
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

HINT

 

Source

【BZOJ1677】[Usaco2005 Jan]Sumsets 求和 递推的更多相关文章

  1. BZOJ1677: [Usaco2005 Jan]Sumsets 求和

    1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 570  Solved: 310[Submi ...

  2. BZOJ 1677: [Usaco2005 Jan]Sumsets 求和

    题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 617  Solved: 344[Su ...

  3. BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )

    完全背包.. --------------------------------------------------------------------------------------- #incl ...

  4. 1677: [Usaco2005 Jan]Sumsets 求和

    1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 626  Solved: 348[Submi ...

  5. BZOJ 1677 [Usaco2005 Jan]Sumsets 求和:dp 无限背包 / 递推【2的幂次方之和】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1677 题意: 给定n(n <= 10^6),将n分解为2的幂次方之和,问你有多少种方 ...

  6. [USACO2005][poj2229]Sumsets(递推)

    http://poj.org/problem?id=2229 分析: 显然的递推 若n为奇数,那么肯定是在n-1的基础上前面每个数+1,即f[n]=f[n-1] 若n为偶数 当第一位数字是1的时候,等 ...

  7. 【BZOJ】1677: [Usaco2005 Jan]Sumsets 求和(dp/规律)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1677 完全背包很容易想到,将1,2,4...等作为物品容量即可. 然后这题还有一个递推式 f[i]= ...

  8. [Usaco2005 Jan]Sumsets 求和

    Description Farmer John commanded his cows to search for different sets of numbers that sum to a giv ...

  9. bzoj 1677: [Usaco2005 Jan]Sumsets 求和【dp】

    设f[i]为i的方案数,f[1]=1,考虑转移,如果是奇数,那么就是f[i]=f[i-1]因为这1一定要加:否则f[i]=f[i-1]+f[i>>1],就是上一位+1或者i/2位所有因子乘 ...

随机推荐

  1. Python 与 C# lambda表达式比较

    Python里到lambda表达式非常简约, lam =lambda a: a*2 --> lam(3) 6 在某些情况下确实挺好用到.但是相比C#到lambda表达式,还是不够强大(我不是在黑 ...

  2. 【翻译三】java-并发之线程对象和实现

    Thread Objects Each thread is associated with an instance of the class Thread. There are two basic s ...

  3. Sencha Architect 安装与使用

    http://www.sencha.com/products/touch/ Sencha SDK Tools Advanced JavaScript and CSS Project Build Too ...

  4. LINQ To DataSet 示例

    如果在项目遇到这样的问题如:DataTable1和DataTable2需要根据一定的规则进行合并成一个DataTable3. 问题1:DataTable1不是读数据库表的结果,而是合成的数据集,因此无 ...

  5. 一些常用的C++标准函数

    一些常用的C++标准函数 double atof(const char* p); int atoi(const char* p); long atol(const char* p); cstdlib ...

  6. C++模板【转】

    1. 模板的概念. 我们已经学过重载(Overloading),对重载函数而言,C++的检查机制能通过函数参数的不同及所属类的不同.正确的调用重载函数.例如,为求两个数的最大值,我们定义MAX()函数 ...

  7. iOS开发资料链接

    ios开发中文文档了 http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOSCh/chap ...

  8. Android使用JNI实现Java与C之间传递数据(转)

    介绍Java如何将数据传递给C和C回调Java的方法.  java传递数据给C,在C代码中进行处理数据,处理完数据后返回给java.C的回调是Java传递数据给C,C需要用到Java中的某个方法,就需 ...

  9. Linux学习笔记(18) Shell编程之流程控制

    1. if语句 (1) 单分支if条件语句 格式为: # 注意条件判断式两端的空格if [ 条件判断式 ];then 程序员 fi 或者 if[ 条件判断式 ] then 程序 fi 例:判断分区使用 ...

  10. SQLServer 本地移动发布/订阅/分发数据库文件并更改逻辑名称和物理文件名

    -------------------------------------------------------------------------------------------------- - ...