题目链接: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. html 元素定位position-relative, absolute, fixed, static

    看到这个,你有什么想法? Difference between static and relative positioning 如果你能完全看明白,那几本上css 元素定位的东西基本都会了.本文也不用 ...

  2. Angular结构简单介绍

    在当前项目目录下,使用Angular-CLI生成一个组件:heroes ng generate component heroes 主界面(也就是一个主模块+多个单模块,例如我们创建的heroes(单模 ...

  3. 各项异性滤波简单介绍Anisotropic Filtering(AF)

    本文主要整理简绍来自互联网的各项异性滤波的知识. 原文链接:http://www.linuxgraphics.cn/graphics/using_anisotropic_texture_filteri ...

  4. How to: Use Submix Voices

    How to: Use Submix Voices:https://msdn.microsoft.com/en-us/library/windows/desktop/ee415794(v=vs.85) ...

  5. 我的家乡:三河古镇已经登上央视CCTV-1新闻联播啦!

    在烟雨朦胧时走在古镇的青石街上,别有一番风味!第一幅图为央视的直播车,第二副图为漂亮的三河夜景色!

  6. Vue常用语法及命令

    1,Vue常用语法 vue常用语法之变量的定义 // 1,变量相关 // 变量的提升 var username = "雪雪"; var username ; console.log ...

  7. HDU 5405 Sometimes Naive 树链剖分+bit*****

    Sometimes Naive Problem Description   Rhason Cheung had a naive problem, and asked Teacher Mai for h ...

  8. accept()函数用来告诉Qt,事件处理函数“接收”了这个事件,不要再传递;ignore()函数则告诉Qt,事件处理函数“忽略”了这个事件,需要继续传递(看一下QWidget::mousePressEvent的实现,最为典型。如果希望忽略事件,只要调用父类的响应函数即可)

    QEvent的accept()和ignore()一般不会用到,因为不如直接调用QWidget类的事件处理函数直接,而且作用是一样的,见下面的例子. 推荐直接调用QWidget的事件处理函数.而不是调用 ...

  9. JavaScript基础简要

    JavaScript   引用外部js :   <script src="2.js"type="text/javascript"></scri ...

  10. svn问题:在eclipse里面使用SVN,怎么实现版本回滚呢?

    共有4个答案 我要回答» JustForFly 回答于 2012-04-27 10:20 举报   想回到SVN服务器端的最新版本就使用 team->还原.. 想回到SVN服务器端的其它版本使用 ...