题目链接: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. App中显示html网页

    在现在的移动开发中,越来越多的web元素增加到了app里面,hybrid app可以综合native app 和 web app的长处,可以通过webView实现 htmllayout.xml: &l ...

  2. Essay

    要养成先连续输入一对匹配的字符——比如"("和")",以及"{"和"}"——再在其中填写内容的习惯.如果先填写内容,很容 ...

  3. JS 省市区三级联动

    JS 省市区三级联动: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  4. 打造极致性能数据库中间件丨LVS+Keepalive+华为云DDM之理论篇

    背景说明 华为云分布式数据库中间件(Distributed Database Middleware,简称DDM),专注于解决数据库分布式扩展问题,突破了传统数据库的容量和性能瓶颈,实现海量数据高并发访 ...

  5. Codevs 2006=BZOJ 2964 Boss单挑战

    2964: Boss单挑战 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 266  Solved: 120[Submit][Status][Discu ...

  6. SpringMVC_配置和注解--跟海涛学SpringMVC(和自己在项目中的实际使用的对比)

    Spring2.5 之前,我们都是通过实现Controller 接口或其实现来定义我们的处理器类,就像前面介绍的 这里介绍的是Spring3.1的新特性,虽然现在我用的是spring4.2.6,不过基 ...

  7. 浏览器同部署了https的服务器交互的过程

    1 浏览器发起https请求 2 https服务器发送自己的公钥给浏览器 3 浏览器用https服务器发送过来的公钥加密一个用于双方通信的的对称密码 4 https服务器用自己的私钥解密,获取对称密码 ...

  8. Django's CSRF mechanism

    Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message because this ...

  9. Spring Cloud 学习总结001-服务治理-Eureka

    学习参考:http://blog.didispace.com/Spring-Cloud%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/ spring cloud由[服务注册中 ...

  10. caioj1271&&poj3071: 概率期望值2:足球

    见到网上的大佬们都用了位运算..表示看不懂就自己想了,还挺好想的(然而我不会告诉你我因为p的数组问题卡了半小时顺便D了ZZZ大佬的数据) DP方程(伪)就是:第t轮第i个队晋级的可能=第t-1轮第i个 ...