Sumsets
Time Limit: 2000MS   Memory Limit: 200000K
Total Submissions: 20315   Accepted: 7930

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

Source

 
 
 
------------------------------------------------------------------------------------------------
分析:按照背包递推即可。
 
#include <cstdio>
#include <algorithm>
using namespace std;
int w[],dp[];
int main()
{
int a=,n;
scanf("%d",&n);
for(int i=;i<=;i++)
{
w[i]=a;
a*=;
}
dp[]=;
for(int i=;i<=;i++)
for(int j=w[i];j<=;j++)
{
dp[j]+=dp[j-w[i]];
dp[j]%=;
}
printf("%d",dp[n]%);
return ;
}

【POJ】2229 Sumsets(递推)的更多相关文章

  1. POJ 2229 Sumsets(递推,找规律)

    构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 ...

  2. poj2229 Sumsets (递推)

    http://poj.org/problem?id=2229 看到题目能感觉到多半是动态规划,但是没有清晰的思路. 打表找规律: #include<cstdio> #include< ...

  3. poj 2506 Tiling 递推

    题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...

  4. hdu2709 Sumsets 递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2709 感觉很经典的一道递推题 自己想了有半天的时间了....比较弱.... 思路: 设f[n]表示和为 ...

  5. POJ 2478 线性递推欧拉函数

    题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...

  6. poj -2229 Sumsets (dp)

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

  7. POJ 2229 Sumsets

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 Descrip ...

  8. Strange Towers of Hanoi POJ - 1958(递推)

    题意:就是让你求出4个塔的汉诺塔的最小移动步数,(1 <= n <= 12) 那么我们知道3个塔的汉诺塔问题的解为:d[n] = 2*d[n-1] + 1 ,可以解释为把n-1个圆盘移动到 ...

  9. poj 2229 Sumsets(dp)

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

  10. poj 2229 Sumsets 完全背包求方案总数

    Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum ...

随机推荐

  1. java项目添加到Tomcat中运行-(项目转换为Dynamic Web Project)

    当在eclipse中建了一个java project项目希望他运行在Tomcat中时: 在项目上右键单击,选择 Properties: 在左侧选择 Project Facets,单击右侧的 ”Conv ...

  2. UCB算法

    前言: 来万物花开这家创业公司实习,也真是一波三折.先实习了三天,每天下午到公司工作到晚上.工作时间是每天下午到晚上9.30.结果每天上午没法用心干实验室的活了,下午在公司工作的时候,总是提心吊胆,手 ...

  3. 初用vue遇到的一些问题

    1.过滤器: filters: { search(list) { es5 var _self = this; //return list.filter(menu => menu.childs.n ...

  4. 关于HTTPS理论和实践

    Summary: HTTP 通信时,可能信息被监听.服务器或客户端身份伪装等安全问题,HTTPS 则能有效解决这些问题. 原始的HTTP连接的时候,因服务器与用户之间是直接进行明文传输,导致用户面临着 ...

  5. 2017《Java技术》预备作业01

    2017<Java技术>预备作业 1.学习使用MarkDown 本学期的随笔都将使用MarkDown格式,要求熟练掌握MarkDown语法,学会如何使用标题,插入超链接,列表,插入图片,插 ...

  6. 关于Django的core first 、db first

    db first 根据数据库的表生成类 django : python manage.py inspectdb code first 根据类创建数据库表: django: python manage. ...

  7. HDU1003 Max Sum

    解题思路:最大连续和,此题多了记录的下标,具体见代码. #include<cstdio> #include<algorithm> using namespace std; #d ...

  8. 报错 Inferred type 'S' for type parameter 'S' is not within its bound; 解决办法

    出现情况: Inferred type 'S' for type parameter 'S' is not within its bound; should extends xxxxxx 出现这种问题 ...

  9. WPF 程序无法触摸操作?我们一起来找原因和解决方法!

    WPF 自诞生以来就带着微软先生的傲慢.微软说 WPF 支持触摸,于是 WPF 就真的支持触摸了.对,我说的是"支持触摸",那种摸上去能点能动的:偶尔还能带点儿多指的炫酷效果.但是 ...

  10. Mybatis新增返回主键的两种方法 (mysql)

    1.自增:LAST_INSERT_ID (自动返回最后一个INSERT或 UPDATE 问询为 AUTO_INCREMENT列设置的第一个 发生的值.) <!-- mysql的自增ID :LAS ...