Sumsets
Time Limit: 2000MS   Memory Limit: 200000K
Total Submissions: 15293   Accepted: 6073

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

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

分两种情况讨论:
当n为奇数时,划分中肯定存在1,那么dp[i]=dp[i-1];
当n为偶数时,可以把划分情况分为含有1和没有1两种情况
  含有1,那么i-1为奇数,dp[i-1];
  不含有1,那么划分中都是偶数,相当于dp[i>>1]的每种划分的两倍;
 #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int M=;
unsigned long long dp[];
int main()
{
unsigned long long n,i,j;
scanf("%lld",&n);
dp[]=;
for(i=;i<=n;i++)
dp[i] = (i% ?dp[i-]:(dp[i-]+dp[i>>]))%M;
printf("%lld\n",dp[n]);
return ;
}

Sumsets(POJ 2229 DP)的更多相关文章

  1. Palindrome(POJ 1159 DP)

      Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 58168   Accepted: 20180 De ...

  2. poj 3311(状态压缩DP)

    poj  3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...

  3. poj 1185(状态压缩DP)

    poj  1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...

  4. poj 3254(状态压缩DP)

    poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...

  5. 【POJ 3140】 Contestants Division(树型dp)

    id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS   Memory Limit: 65536K Tot ...

  6. 【POJ 2486】 Apple Tree(树型dp)

    [POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8981   Acce ...

  7. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  8. dp乱写1:状态压缩dp(状压dp)炮兵阵地

    https://www.luogu.org/problem/show?pid=2704 题意: 炮兵在地图上的摆放位子只能在平地('P') 炮兵可以攻击上下左右各两格的格子: 而高原('H')上炮兵能 ...

  9. HDU 2457 DNA repair(AC自动机+DP)题解

    题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了.既然是多模匹配,我们是要用到AC自动机的.我们把主串放到AC自动机上跑,并保证不出现 ...

随机推荐

  1. hdu 2034

    Problem Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法 ...

  2. 使用Hexo搭建GitPage

    资料: hexo官方文档:https://hexo.io/zh-cn/docs/ jekyll官方文档:http://jekyll.com.cn/docs/home/ 简介: 使用hexo和jekyl ...

  3. Log4net 配置详解

    首先需在config文件的<configSections>节点中增加子节点配置. <configSections> <section name="log4net ...

  4. Bash: how to check if a process id (PID) exists

    http://stackoverflow.com/questions/3043978/bash-how-to-check-if-a-process-id-pid-exists https://bugz ...

  5. java package 重命名时注意事项

    如果要对包重命名时,需要关注以下方面: 1. java关联类里的重命名(这个一般通过开发工具会自动修正,如eclipse) 2.配置文件,如原先配置为com.abc,现在更名为com.abc123,这 ...

  6. linux 网络Socket实战

    Preface:就算调通API,也不值得太过自豪!!!悉心细心学习,最好的深度学习就是看-学...*.h/*.class ProtoType; 1,linux C ftp C/S简单实现 ftpS端码 ...

  7. 关于padding

    例子 1 padding:10px 5px 15px 20px; 上内边距是 10px 右内边距是 5px 下内边距是 15px 左内边距是 20px 例子 2 padding:10px 5px 15 ...

  8. LitJson处理Json

    LitJSON是一个.NET平台下处理JSON格式数据的类库,小巧.快速.它的源代码使用C#编写,可以通过任何.Net平台上的语言进行调用,目前最新版本为LitJSON 0.9. 下载地址: http ...

  9. Scala-Partial Functions(偏函数)

    如果你想定义一个函数,而让它只接受和处理其参数定义域范围内的子集,对于这个参数范围外的参数则抛出异常,这样的函数就是偏函数(顾名思异就是这个函数只处理传入来的部分参数). 偏函数是个特质其的类型为Pa ...

  10. Android将第三方jar打包进apk

    转自:http://blog.csdn.net/liushaogeng/article/details/6641704 使用第三方jar包 除了我以下介绍的方法,别的方法我基本上都试验过,均会出现编译 ...