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. 【SQL查询】分区查询Over

    1. Over介绍 Over为开窗函数.就是把满足条件的数据分成几个区域,每个区域可以通过像现实中的“窗口”来观察统计这些数据. over不能单独使用,要和分析函数:rank(), dense_ran ...

  2. 桔子桑Blog(小程序)V 0.4

    这两天对这个个人博客小程序的UI又作了一些补充,目前看来,小程序的主要功能如下: 1.博客/日常栏目的导航切换 为了避免两个模块的UI上的过于单一,我将两个模块的列表页作了区分: 边距是自适应的(针对 ...

  3. 《Unity 3D游戏客户端基础框架》系统设计

    引言 最近到看一个 <贪吃蛇大战开发实例>,其中 贪吃蛇大作战游戏开发实战(3):系统构架设计 提供的系统架构的设计思路我觉得还是值得学习一下的,接下来的内容是我看完视频后的一点笔记. 架 ...

  4. caffe学习3——layers

    1 layer是模型的本质,是计算的基本单元.Layers convolve filters, pool, take inner products, apply nonlinearities like ...

  5. [转]MongoDB c++驱动安装与使用

    安装 获取源码:git clone https://github.com/mongodb/mongo-cxx-driver.git,解压 安装编译工具scons:yum install -y scon ...

  6. CF1130E Wrong Answer

    E Wrong Answer 注意到 \(n\geq 2\) 时才可能有解,可以按如下方式构造一个 \(a_{1,2\dots n}\): 令 \(a_1=-1\) ,而后面的数都为正.记 \(s=\ ...

  7. Roslyn 入门:使用 .NET Core 版本的 Roslyn 编译并执行跨平台的静态的源码

    Roslyn 是微软为 C# 设计的一套分析器,它具有很强的扩展性.以至于我们只需要编写很少量的代码便能够编译并执行我们的代码. 作为 Roslyn 入门篇文章之一,你将可以通过本文学习如何开始编写一 ...

  8. HTTP Client Performance Improvements

    HTTP Client Performance Improvements https://blogs.msdn.microsoft.com/webdev/2018/10/17/asp-net-core ...

  9. 微信小程序(1)——小程序的特点以及结构

    简单的,用完即走的应用 低频应用 性能要求不高的应用 应用程序入口(app.js   app.json  app.wxss) 一级页面:wxml,wxss,js,json 二级页面:wxml,wxss ...

  10. Tornado之架构概述图

    一.Tornado之架构概述图 二.Application类详细分析: #!/usr/bin/env python # -*- coding: utf8 -*- # __Author: "S ...