完全背包..

---------------------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ; i < n ; i++ )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
#define mod( x )  ( ( x ) %= 1000000000 )
 
const int maxn = 1000000 + 5;
 
int d[ maxn ];
 
int main() {
freopen( "test.in" , "r" , stdin );
int n;
cin >> n;
clr( d , 0 );
d[ 0 ] = 1;
for( int i = 0 ; ( 1 << i ) <= n ; i++ )
   for( int j = 1 << i ; j <= n ; j++ )
       mod( d[ j ] += d[ j - ( 1 << i ) ] );
       
cout << d[ n ] << "\n";
return 0;
}

---------------------------------------------------------------------------------------

1677: [Usaco2005 Jan]Sumsets 求和

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 666  Solved: 367
[Submit][Status][Discuss]

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

BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )的更多相关文章

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

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

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

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

  3. 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位所有因子乘 ...

  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/规律)

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

  6. BZOJ1677: [Usaco2005 Jan]Sumsets 求和

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

  7. 【BZOJ1677】[Usaco2005 Jan]Sumsets 求和 递推

    ... #include <iostream> using namespace std; ]; int n,i; int main() { cin>>n; f[]=; ;i&l ...

  8. [Usaco2005 Jan]Sumsets 求和

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

  9. BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )

    一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...

随机推荐

  1. easyui-layout中的收缩层无法显示标题问题解决

    先看问题描述效果图片: 如上,我的查询条件是放在layout下面的一个可收缩层中,初始是收缩的,title显示不出来的话对使用者很不方便,代码如下: <div id="__MODULE ...

  2. cocos2d-x 多点触控实现缩放及相关问题的解决方法

    首先,来看下代码: 声明文件: #ifndef __loading__MoreTouches__ #define __loading__MoreTouches__ #include <iostr ...

  3. redis 缓存技术与memcache的最大差别

    1 什么是redis  redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对很多其它,包含string(字符串).list(链表).set(集合)和zs ...

  4. GridView行编辑、更新、取消、删除事件使用方法

    注意:当启用编辑button时,点击编辑button后会使一整行都切换成文本框.为了是一行中的一部分是文本框,须要把以整行的全部列都转换成模板,然后删掉编辑模板中的代码.这样就能使你想编辑的列转换成文 ...

  5. linux之iptable案例

    转自:http://blog.csdn.net/bill_lee_sh_cn/article/details/4401896 1.一对一流量完全DNAT 首先说一下网络环境,普通主机一台做防火墙用,网 ...

  6. <精华篇>:iOS视频大全-持续更新

    注意:新浪微博分享的资料和简书分享的资料,略有不同! 小码哥swift3.0版 斗鱼项目视频:点击下载  iOS开发25个项目实战:点击下载 2016PHP全套下载:点击下载  黑马刀哥iOS视频精选 ...

  7. ajax异步服务器获取时间

    1.创建ajax对象 <script type="text/javascript"> //创建AJAX异步对象 function createAJAX(){ var a ...

  8. win7 64位 Xsheel

    Xsheel5安装后,找不到.dll文件,系统支持不好,不用 Xshell4有时提示 1152:Error 就使用 链接:http://pan.baidu.com/s/1c1s42Y0 密码:098x ...

  9. c++ 简单的词法分析

    scanner.h #include<iostream> #include<fstream> #include<string> using namespace st ...

  10. hdu 3333 Turing Tree

    题目链接 给n个数, m个询问, 每次询问输出区间内的数的和, 相同的数只计算一次. 数组里的数是>-1e9 <1e9, 可以把它离散以后用莫队搞... #include <iost ...