题目链接: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. MVC在View中页面跳转

    在做人事系统的时候须要用到页面跳转,那么页面跳转究竟用什么方法好呢?依照曾经的思路,我就会这么写. <span style="font-size:18px;">wind ...

  2. 【Mongodb教程 第十五课 】MongoDB 限制记录

    Limit() 方法 要限制 MongoDB 中的记录,需要使用 limit() 方法. limit() 方法接受一个数字型的参数,这是要显示的文档数. 语法: limit() 方法的基本语法如下 & ...

  3. CSS 相对|绝对(relative/absolute)定位系列(一)

    一.有话要说 以前写内容基本上都是:眼睛一亮——哟呵,这个不错,写!然后去古人所说的茅房里蹲会儿,就有写作的思路了.但是,构思相对/绝对(relative/absolute)定位系列却有好些时日,考虑 ...

  4. FancyCoverFlow

    https://github.com/davidschreiber/FancyCoverFlow

  5. React通过Ajax获取数据

    React 组件的数据可以通过 componentDidMount 方法中的 Ajax 来获取,当从服务端获取数据库可以将数据存储在 state 中,再用 this.setState 方法重新渲染 U ...

  6. 计算机体系结构的铁律(iron law)

    计算机体系结构的铁律可由下面公式来描写叙述: 从Programmer的角度来看,处理器的性能就是运行程序的耗费的时间.所以用Time/Program来刻画处理器性能.而这个简单的公式背后是有很丰富的内 ...

  7. 6.游戏特别离不开脚本(3)-JS脚本操作java(2)(直接解析JS公式,并非完整JS文件或者函数)

    在游戏中可以考虑数据由javabean保存,逻辑方法由JS提供. public class Bean4JS { private int id; private String name; private ...

  8. Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.0. Could not resolve com.android.support.constraint:constraint-l

    File->Settings->Build, Execution, Deployment->Gradle->取消选中 Offline work 按钮

  9. Linux 杀死所有进程

    方法一: sudo killall -9 netease-cloud-music 这种方法,必须要写全称. sudo netease-cloud-music QStandardPaths: XDG_R ...

  10. qemu-kvm磁盘读写的缓冲(cache)的五种模式

    qemu-kvm磁盘读写的缓冲(cache)模式一共有五种,分别是writethrough, wirteback, none, unsafe, directsync当你对VM读写磁盘的性能有不同的要求 ...