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
#include<iostream>
#include<algorithm>
using namespace std;
int dp[];
int mod=1e9;
int main(){
int n;
cin>>n;
dp[]=;
for(int i=;i<=n;i++){
if(i%==){
dp[i]=dp[i-];
}
else{
dp[i]=(dp[i-]+dp[i>>])%mod;
}
}
cout<<dp[n]<<endl;
return ;
}

POJ2229--Sumsets(动态规划)的更多相关文章

  1. POJ2229 Sumsets 【递归】

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 13210   Accepted: 5300 Descrip ...

  2. poj2229 Sumsets (递推)

    http://poj.org/problem?id=2229 看到题目能感觉到多半是动态规划,但是没有清晰的思路. 打表找规律: #include<cstdio> #include< ...

  3. POJ2229 Sumsets

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 19024   Accepted: 7431 Descrip ...

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

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

  5. POJ2229 - Sumsets(完全背包)

    题目大意 给定一个数N,问由不同的2的幂之和能组成N的方法有多少种 题解 看完题目立马想到完全背包...敲完代码上去超时了....后来发现是%的原因...改成减法就A了...%也太他妈耗时了吧!!!( ...

  6. 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280

    POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...

  7. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. 子集和问题(应用--换零钱)POJ2229:Sumsets

    我一直在纠结换零钱这一类型的题目,今天好好絮叨一下,可以说他是背包的应用,也可以说他是单纯的dp.暂且称他为dp吧. 先上一道模板题目. sdut2777: 小P的故事——神奇的换零钱 题目描述 已知 ...

  10. 【动态规划】POJ-2229

    一.题目 Description Farmer John commanded his cows to search for different sets of numbers that sum to ...

随机推荐

  1. python学习笔记Day2

    字符编码 编程规范(PEP8) 变量1.常量(用大写) 2.变量 常用类型:str .int.float. long.bool 字串格式化: %d 整数 %2d占两位 %02d占两位用0填充 %f 浮 ...

  2. 关于transform-style:preserve-3d的些许明了

    父元素要添加属性transform-style:preserve-3d;和transform:perspective(800px);还有相对定位 首先设置子元素 具有3D属性,然后再设置视角与3D元素 ...

  3. overflow visibility opacity(透明度) vertical-align 等等

     一,overflow属性:   1,四个值:    visible     默认值.内容不会被修剪,会呈现在元素框之外.    hidden        内容会被修剪,并且其余内容是不可见的.   ...

  4. HTML标签归纳

    首先,按下h1,再按下Tab键就可以变成<h1></h1>,Ctrl+d可以复制当前行,Ctrl+Alt+Insert可以快速新建文件,Home可以跳到当前行最前面,End同理 ...

  5. ES6解构赋值的应用场景

    一.变量交换 1.ES6的方式 { let a=; let b=; [a,b]=[b,a]; console.log(a,b); } 输出为 2.ES5的方式 采用中间变量的方式进行存储 二.获取函数 ...

  6. 利用Swoole编写一个TCP服务器,顺带测试下Swoole的4层生命周期

    1首先我们写一个入口脚本,这里简单点的功能就是开启服务和关闭服务 <?php //CLI命令 if(isset($argv[1]) && in_array($argv[1], [ ...

  7. phpstorm的安装和使用

    1下载phpstorm #下载地址 https://www.jetbrains.com/phpstorm/ 2激活并安装 create associations 表示的是以后编辑选择的文件也默认用id ...

  8. oracle sqlplus操作

    步骤: su - oracle 切换到oracle用户 sqlplus /nolog 进入sqlplus命令行 conn cps/cps 连接到cps用户的数据库,cps/cps表示:用户/密码 执行 ...

  9. Luogu 2812 校园网络 - Tarjan

    Description 给出一个有向图, 要求出至少从哪几个点出发, 能不漏地经过所有节点. 再求出至少加几条边, 才能使图变成一个强联通分量 Solution 求出所有强联通分量, 形成一个有向无环 ...

  10. debian9安装mysql mariadb

    debian9下mysql 替换成mariadb-server-10.1 不过两者类似 具体可见 <MySQL和mariadb区别> http://ask.chinaunix.net/qu ...