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

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>
int a[1000005];
int mod=1e9;
int dp[355][355];
int main ()
{int i,n;
a[1]=1;
a[2]=2;
for(i=3;i<=1000000;i++)
if(i&1) a[i]=a[i-1];
else a[i]=(a[i-2]+a[i>>1])%mod;
while(~scanf("%d",&i))
{
printf("%d\n",a[i]);
}
return 0;
}

好经典的题目。居然a[2]忘记给值了~

POJ 2229 Sumsets的更多相关文章

  1. poj -2229 Sumsets (dp)

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

  2. poj 2229 Sumsets(dp)

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

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

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

  4. poj 2229 Sumsets DP

    题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...

  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(技巧题, 背包变形)

    discuss 看到有人讲完全背包可以过, 假如我自己做的话, 也只能想到完全背包了 思路: 1. 当 n 为奇数时, f[n] = f[n-1], 因为只需在所有的序列前添加一个 1 即可, 所有的 ...

  9. POJ 2229 Sumsets(规律)

    这是一道意想不到的规律题............或许是我比较菜,找不到把. Description Farmer John commanded his cows to search for diffe ...

随机推荐

  1. 简单利用Scanner对文件进行解析

    public class AvPrice{    static int count = 0;    static int sum = 0;    public static void main(Str ...

  2. 1.Dotnet Core安装

    DtnetCore1.0.1的安装包我以上传至百度网盘,里面有安装教程. http://pan.baidu.com/s/1c2iLNNE 如果安装不上,请留言,我会在第一时间回复你. 不需要挂VPN.

  3. unreal slate 创建 window

    testWindow = SNew(SWindow) .Title(LOCTEXT("Asset Window", "Asset Window")) .Clie ...

  4. Django + mysql 快速搭建简单web投票系统

    了解学习pyhton web的简单demo 1. 安装Django, 安装pyhton 自行百度 2. 执行命令创建project  django-admin.py startproject mysi ...

  5. Linux-ubuntu指令使用积累(长期更新)

    alias cat cd cp ls mkdir mv rm sudo tar chmod       1. sudo 系统管理指令.放在其它指令之前使用,允许普通用户在root权限下执行部分或者全部 ...

  6. MFC编程入门之二十四(常用控件:列表框控件ListBox)

    前面两节讲了比较常用的按钮控件,并通过按钮控件实例说明了具体用法.本文要讲的是列表框控件(ListBox)及其使用实例. 列表框控件简介 列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选 ...

  7. hadoop启动是常见小问题

    1.先su进入root账户,然后 service iptables stop //关闭防火墙 start-all.sh //启动 2.启动是会显示,如果出错日志保存路径!!!基本所有问题都要去这些日志 ...

  8. PHP data

  9. Lander-Waterman model

    参考: Lander-Waterman Model 这个模型是鸟枪法测序和基因组装的最基本的理论模型,它揭示了测序深度与覆盖度之间的关系. 该模型回答了一个最基本的问题:How many reads ...

  10. 【oracle】 oracle学习笔记1--安装与登录

    由于机器配置原因,加上也是自学,所以就没必要安装专业版的oracle,于是就安装的oracle xe版本 下载地址:http://www.oracle.com/technetwork/database ...