完全背包..

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

#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. Qt项目管理(33个规则)

    2016-06-20 花莫弦 小小杂货铺LY 一.qmake的介绍 qmake是Trolltech公司创建的用来为不同的平台和编译器书写Makefile的工具. 手写Makefile是比较困难并且容易 ...

  2. centos6.5设备mysql5.6

    1. 首先检查版本号number # uname -a 要么 # cat /etc/redhat-release CentOS release 6.6 (Final) 2. 下载并安装Mysql的yu ...

  3. Apache Mina开发手冊之四

    Apache Mina开发手冊之四 作者:chszs,转载需注明. 博客主页:http://blog.csdn.net/chszs 一.Mina开发的主要步骤 1.创建一个实现了IoService接口 ...

  4. WCF 双工通信

    注释:本学习是参考Artech大神的资料: 在WCF 实现双工通信 在这里我就不介绍双工通信的概念了,我写博客的目的是检测自己掌握情况,看我wcf通信后,觉得纸上得来终觉浅,绝知此事要躬行. 我使用的 ...

  5. 2014-07-23 利用ASP.NET自带控件实现单文件上传与下载

    效果图 上传文件页面: 下载文件页面:  1.母版页site.Master <%@ Master Language="C#" AutoEventWireup="tr ...

  6. LINQ实现行列转换

    用SQL语句实现行列转换很容易,但也有时候需要在程序中实现,找了好久,发现一篇文章写的挺不错的 http://blog.csdn.net/smartsmile2012/article/details/ ...

  7. myeclipse优化设置

    一.myeclipse字体设置Window->Preferences->General->Appearance->Colors and Fonts在右侧找到”Aa Test F ...

  8. 【转载】VC++中的图像类型转换--使用开源CxImage类库

    一.CxImage类库简介 这只是翻译了CxImage开源项目主页上的部分简介及简单使用. CxImage类库是一个优秀的图像操作类库.它可以快捷地存取.显示.转换各种图像.有的读者可能说,有那么多优 ...

  9. Map(关联式容器)

    map是一类关联式容器,自动建立Key - Value的对应 , key 和 Value可以是任意你需要的类型.下面介绍 map 中一些常用的函数: 一.map 中的 begin 和 end 函数 m ...

  10. 使用iscroll4可能会遇到的问题(转:记录)

    1.在iscroll4的滚动容器范围内,点击input框.select等表单元素时没有响应这个问题原因在于iscroll需要一直监听用户的touch操作,以便灵敏的做出对应效果,所以它把其余的默认事件 ...