题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2709

Problem 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

农夫约翰命令他的母牛寻找不同的数字集合,这些数字集合到一个给定的数字中。 奶牛只使用2的整数次幂。以下是可能的总和为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

帮助FJ计算给定整数N(1 <= N <= 1,000,000)的所有可能表示。

输入

  带单个整数的单行,N

输出

  将N表示为表示总和的方式的数量。 由于这个号码可能有很大的尺寸,只能打印最后9位数字(以10为底数表示)。

解题思路:这是一道找规律的数学题,意思就是给定一个数N,找出所有1~N中是2的整数次幂的因子的和,(因子可以重复)。

简单举个栗子:当N=3时,有1+1+1=3;1+2=3,共两种情况,所以按照这样的规则,多找出后面几个数,即可找到规律。其规律如下:

      数字N=  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16...
总和为N的方式数:1  2  2  4  4  6  6  10 10 14  14  20  20  26  26  36...
由以上规律可得当N为奇数时,a[i]=a[i-1]%mod;(i是数字)
当N为偶数时,a[i]=(a[i-1]+a[i/2])%mod;(i>=2)(mod=1e9)
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int n,a[];
int main()
{
a[]=,a[]=;
for(int i=;i<;i++){
if(i%)a[i]=a[i-]%;//奇数
else a[i]=(a[i-]+a[i/])%;//偶数
}
while(cin>>n)
cout<<a[n]<<endl;
return ;
}

题解报告:hdu 2709 Sumsets的更多相关文章

  1. HDU 2709 Sumsets(递推)

    Sumsets http://acm.hdu.edu.cn/showproblem.php?pid=2709 Problem Description Farmer John commanded his ...

  2. HDU - 2709 Sumsets 【递推】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2709 题意 给出一个数N 要求有多少种方式 求和 能够等于N 加的数 必须是 2的幂次 思路 首先可以 ...

  3. hdu 2709 Sumsets

    Sumsets Time Limit: 6000/2000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. HDU 2709 Sumsets 经典简单线性dp

    Sumsets Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  6. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  7. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  8. 2015浙江财经大学ACM有奖周赛(一) 题解报告

    2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...

  9. cojs 强连通图计数1-2 题解报告

    OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...

随机推荐

  1. Centos 5.11 samba

    1.使用yum安装samba,添加samba user yum install samba samba-client samba-swatuseradd smbuser -m             ...

  2. Linux如何更新软件源

    Linux软件源的设置方法 1 打开数据源配置文件 vi /etc/apt/sources.list     添加相关的数据源,可以选择以下的数据源,不要写太多,否则会影响更新速度.   之后使用ap ...

  3. 相机标定(Camera calibration)

    简单介绍 摄像机标定(Camera calibration)简单来说是从世界坐标系换到图像坐标系的过程.也就是求终于的投影矩阵 P 的过程,以下相关的部分主要參考UIUC的计算机视觉的课件(网址Spr ...

  4. leetCode 67.Add Binary (二进制加法) 解题思路和方法

    Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...

  5. sysinfo 系统调用

    在分析luci时,看到 usr/lib/luci/sys.lua 里调用 nixio.sysinfo().这是一个c调用lua的用例.在nixio的代码process.c里导出了给lua调用的接口.在 ...

  6. JSON序列化-化繁为简

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. iOS 开发者中的个人账号与组织账号之间区别

    苹果对开发者主要分为3类:个人.组织(公司.企业).教育机构.即: 1.个人(Individual) 2.组织(Organizations) 组织类又分为2个小类: (1)公司(Company) (2 ...

  8. Android调用本地WebService

    package com.example.testinvokewebservice; import org.ksoap2.SoapEnvelope; import org.ksoap2.serializ ...

  9. Hackrank Kingdom Division 树形DP

    题目链接:传送门 题意: 给你一棵树,n个点 每个点可以染成红色和蓝色 但是红色的点与其相邻的点中必须有红色节点,蓝色也是 问你有多少种染色的方案 题解: 树形dp 先转化为有根树,取1为根 设定dp ...

  10. 设计模式-(6)适配器 (swift版)

    用来解决接口适配问题的三种模式:适配器模式,桥接模式,外观模式. 一,概念 适配器模式,将一个类的结构转换成用户希望的另一个接口,使得原本接口不兼容的类能在一起工作.换句话说,适配器模式就是链接两种不 ...