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. JDK Windows环境配置

    [CLASSPATH] .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar [JAVA_HOME] D:\Java\jdk1.8.0_11 [Path] %JAVA ...

  2. Xcode中C、C++、Object-C3种语言的混编

    转自: http://hi.baidu.com/onejw/item/f34390c997cdc226a1b50ae http://www.cocoachina.com/ask/questions/s ...

  3. heritrix 3.2.0 下载

    由于archive.org屏蔽,编译完成版本 http://builds.archive.org/maven2/org/archive/heritrix/heritrix/3.2.0/ 无法下载. 现 ...

  4. POJ3278 Catch That Cow(BFS)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  5. OPStackComputeNodeMaintain

    1,yum -y install openstack-nova-compute计算节点配置完成后 其配置文件默认非注释行内容如下;

  6. JAVA获得系统配置文件的System Properties

    来个java获得系统配置文件的 public class SystemProperties { public static void main(String[] args) { Properties ...

  7. PHP文件目录copy

    /**(2) PHP文件目录copy @param string $dirsrc 原目录名称字符串 @param string $dirto 目标目录名称字符串 */ function copyDir ...

  8. IOS 退出App

    UIApplication *app = [UIApplication sharedApplication]; [app performSelector:@selector(suspend)]; // ...

  9. [Ionic] Build and Run an Ionic App from Scratch

    Install: npm install ionic cordova -g Create a project with blank template: ionic start <project_ ...

  10. BOOST 线程完全攻略 - 基础篇

    http://blog.csdn.net/iamnieo/article/details/2908621 2008-09-10 12:48 9202人阅读 评论(3) 收藏 举报 thread多线程l ...