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. HBase数据存储

    HRegionServer  HBase的数据文件都存储在HDFS上,格式主要有两种: - HFile:HBase中KeyValue数据的存储格式,HFile是Hadoop的二进制文件,实际上Sto ...

  2. Happy Swifting!

    Happy Swifting! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  3. web前端开发中的命名规范

      (一)主体 头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中: ...

  4. BitArray编写埃拉托斯特尼筛法(原书错误,学习更正)

    刚开始代码无法运行,修改后原书代码可以运行了,可是书本的思想还是错的. 虽然接下来的都是讲错误的思想下的“错误”的修改. 原书缺了窗体控件的代码,虽然在VS下不需要手动写窗体的代码,但是刚开始确实也不 ...

  5. Android常见问题——找不到HttpClient和okHttp的包

    今天再用Android Studio进行网络编程的时候遇到了一个问题,就是怎么也找不到HttpClient的包,上网搜了一下也没什么结果,但最后偶然解决问题,下面总结了一下方法: 首先打开File-& ...

  6. 8.另类方法求1+2+...+n[AnotherMethodOfCalculateSumN]

    [题目] 求1+2+…+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句(A?B:C). [分析] 这道题没有多少实际意义,因为在软件开发中不 ...

  7. wampserver2.5的php.ini位置在wamp\bin\apache\apache2.4.9\bin

    wampserver2.5的php.ini位置在wamp\bin\apache\apache2.4.9\bin php.ini有多个地方,C:\wamp\bin\php\php5.5.12下面有php ...

  8. 页面提交 string数组和list对象集合举例

    ajax表单提交   $.ajax({                 cache: true,                 type: "POST",             ...

  9. BZOJ4903 UOJ300 CTSC2017 吉夫特 【Lucas定理】

    BZOJ4903 UOJ300 CTSC2017 吉夫特 弱弱地放上题目链接 Lucas定理可以推一推,发现C(n,m)是奇数的条件是n" role="presentation&q ...

  10. css 样式常用属性

    一般的一个DIV的CSS设置属性有:margin,padding,width,height,font-size,text-align,background,float,border 附:< cs ...