完全背包..

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

#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. CCNA实验(5) -- OSPF

    enableconf tno ip do loenable pass ciscoline con 0logg syncexec-t 0 0line vty 0 4pass ciscologg sync ...

  2. C#实现 ffmpeg视频转码、播放

    近来公司项目要求实现全景相机的视频截取,但是截取的视频需求转码上传.经过研究采用ffmpeg转码,奉上一个详细介绍的博文: 最简单的基于FFMPEG的转码程序 主要是转码的操作过程,能够实现了从相机获 ...

  3. 优步uber司机怎么注册不了?注册优步司机问题要点

    第一,可能是你的车型不符全要求,看是不是5年内的车型,同时要求车价8W以上:第二,你的驾驶年限不够,要求驾驶证年限1年以上的,如果不够的怎么办,告诉你个方法,PS啊!优步可查不了车管所的系统,所以这类 ...

  4. android环境下解决java.io.IOException: Malformed ipv6异常的方法

    今天做客户端想服务端提交信息的时候,报出了如标题所显示的方法 方法以及参数如下: 输入的参数为:http://192.168.1.173:8080/Api/petinfo/petinfo?flag=a ...

  5. SGU326Perspective(网络流量的最大流量)(经典赛车模型)

    职务地址:http://acm.sgu.ru/problem.php? contest=0&problem=326 额,这题读错题了...又WA了好长时间...坚持不看题解也挺浪费时间的..早 ...

  6. linux核心之进程管理

    进程就是处于执行期的程序(目标码存放在某中介质上).进程并不仅仅局限于一段可执行程序代码,通常还包括其他资源,例如打开的文件,挂起的信号,内核内部数据,处理器状态,一个或多个具有内存映射的内存地址空间 ...

  7. system.io.file创建

    在实际开发中,如果用的文件名不能确定位置.或名字.可以使用GUID类来命名函数.Guid 结构标识全局唯一标示符.其NewGuid结构可以初始化一个新历.该方法语法格式如下: public stati ...

  8. 七日筑基——C#第二天

    上一次讲到了变量,变量这个东西可以说是编程的基础,主要的作用就是用来存放数据,就跟做菜一样的,不同的菜要放在不同类型的容器中,那么不同的数据也需要存放在不同类型的变量里.先放张饭菜的图给大家看看,增加 ...

  9. C# 课堂总结3-语句

    一.顺序语句 二.条件,分支语句 1.if语句 关键是能够熟练运用 if的嵌套.要考虑好所有的情况. 如果说 条件是两种+情况相互对应的,那么就可以只用 if 与else .但必须要想好 每个else ...

  10. Java 比较两日期相差天数

    (版本1) publicstaticint getIntervalDays(Date fDate, Date oDate) { if (null == fDate || null == oDate) ...