Sumsets

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

思路:用完全背包的方法做,状态转移方程:dp[j]+=dp[j-v](j>=v)
代码:
 #include "cstdio"
#include "algorithm"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
typedef long long ll;
using namespace std;
const int N=1e6+;
const int Mod=1e9;
#define db double
int n;
int dp[N];
void solve(){
memset(dp,,sizeof(dp));
dp[]=dp[]=;
for(int i=;i<;i++){
int v=<<i;
for(int j = ;j<=N;j++){
if(j>=v) dp[j]+=dp[j-v];
while (dp[j]>=) dp[j]-=;
}
}
}
int main(){
solve();
while(scanf("%d",&n)==){
printf("%d\n",dp[n]);
}
return ;
}

poj 2229 DP的更多相关文章

  1. Sumsets(POJ 2229 DP)

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

  2. poj 2229 【完全背包dp】【递推dp】

    poj 2229 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 21281   Accepted: 828 ...

  3. poj -2229 Sumsets (dp)

    http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...

  4. DP:Sumsets(POJ 2229)

     数的集合问题 题目大意:给定你一个整数m,你只能用2的k次幂来组合这个数,问你有多少种组合方式? 这一题一看,天啦太简单了,完全背包?是不是? 不过的确这一题可以用完全背包来想,但是交题绝对是TLE ...

  5. poj 2229 Sumsets(dp 或 数学)

    Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...

  6. poj 2229 Sumsets(记录结果再利用的DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 将一个数N分解为2的幂之和共有几种分法? 题解: 定义dp[ i ]为数 i 的 ...

  7. POJ 2229 Sumsets【DP】

    题意:把n拆分为2的幂相加的形式,问有多少种拆分方法. 分析:dp,任何dp一定要注意各个状态来源不能有重复情况.根据奇偶分两种情况,如果n是奇数则与n-1的情况相同.如果n是偶数则还可以分为两种情况 ...

  8. poj 2229 Sumsets(dp)

    Sumsets Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 400000/200000K (Java/Other) Total Sub ...

  9. POJ 2229 计数DP

    dp[i]代表是数字i的最多组合数如果i是一个奇数,i的任意一个组合都包含1,所以dp[i] = dp[i-1] 如果i是一个偶数,分两种情况讨论,一种是序列中包含1,因此dp[i]=dp[i-1]一 ...

随机推荐

  1. redis 2 字符串 和 hash

    string是最简单的类型,一个key对应一个value,string类型是二进制安全的.redis的string可以包含任何数据,比如JPG图片或者序列化的对象 操作    set    设置key ...

  2. nginx的配置服务器集群,负载均衡

    在server{}前配置服务器ip和端口号 如: upstream local_tomcat { local_tomcat为访问路径,在下面配置服务器ip及端口号,也可以分配权重(weight==?) ...

  3. 我的Linux系统的VIMRC

    " llvm CODING GUIDELines conformance for VIM" $Revision$"" Maintainer: The LLVM ...

  4. paramiko库安装

    python的paramiko库用于执行ssh2连接(client和server).安装方式如下: 硬件环境:Raspberry 2B,arm,1GB RAM,16GB TF卡; 系统环境:Linux ...

  5. ubuntu下安装ssh服务器方法

    由于xshell远程连接ubuntu是通过ssh协议的,所以,需要给ubuntu安装ssh服务器. 1)ubuntu安装ssh服务器 sudo apt-get install openssh-serv ...

  6. js之Math对象

    ; var num1 = Math.floor(num); // 向下取整 var num2 = Math.ceil(num); // 向上取整 document.write(num2+'-<b ...

  7. Ceph QoS 初探(下)

    作者:吴香伟 发表于 2017/01/24 版权声明:可以任意转载,转载时务必以超链接形式标明文章原始出处和作者信息以及版权声明 存储QoS是个可以做很大也可以做很小的特性.SolidFire认为将Q ...

  8. 毕向东udp学习笔记2

    项目功能:  发送端读取控制台输入,然后udp发送 接收端一直接收,直到输入为886 相对于笔记1,修改了发送端代码,实现发送控制台的内容,接收端循环接收,当输入886时,停止发送 发送端: impo ...

  9. Qt之hello world

    本人使用的是Qt5.7版本的,请读者自主下载安装. 今天首先来进行Qt入门的第一个程序,也是很经典的一个例子.这是在很多的变成语言中都会用到的例子,就是输出helloworld这个信息.Qt中使用的变 ...

  10. Asp.net mvc 知多少(七)

    本系列主要翻译自<ASP.NET MVC Interview Questions and Answers >- By Shailendra Chauhan,想看英文原版的可访问http:/ ...