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).

InputA single line with a single integer, N.OutputThe 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
题目大意就是将一个整数拆分为只有 1 或者 有 1 和偶数(2的次方数)组分的几个数的和

当于在f[n-1]的拆分结果上增加一个 1 即可;

当整数n为偶数时,分为两种情况,含有1 ,和不含有1;

含有1时,就是f[n-1],不含1时,就是f[n/2](拆分结果都除以2)的结果

综上结果,得出打表公式:

f[1]=1;   f[2]=2;

f[n]=f[n-1]              //n是奇数

f[n]=f[n-1]+f[n/2]   //n是偶数

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[];
int main()
{
int n;
a[] = ;
a[] = a[] = ;
a[] = a[] = ;
for(int i=;i<=;i++)
{
if(i%==)
a[i] = (a[i-] + a[i/])%;//这里取i/2的值
else a[i] = a[i-]%;
}
while(cin >> n)
{
cout << a[n] << endl;
}
return ;
}

hdu 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

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

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

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

  4. HDU - 2709 Sumsets 【递推】

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

  5. 题解报告:hdu 2709 Sumsets

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2709 Problem Description Farmer John commanded his co ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Hadoop 系列(二)—— 集群资源管理器 YARN

    一.hadoop yarn 简介 Apache YARN (Yet Another Resource Negotiator) 是 hadoop 2.0 引入的集群资源管理系统.用户可以将各种服务框架部 ...

  2. BFS DFS模板

    转载于https://blog.csdn.net/alalalalalqp/article/details/9155419 BFS模板: #include<cstdio> #include ...

  3. 七天学会NodeJS——第一天

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:http://nqdeng.github.io/7-days-nodejs Node.js 是一个能 ...

  4. WPF中ComboBox控件绑定键值对操作

    WPF中下拉框将键值对作为其数据源的具体操作.本实例以枚举类型以及枚举特性描述字符串生成键值对来进行. namespace ViewC { /// <summary> /// View.x ...

  5. eclipse项目导入idea jdk版本不一致😵

    在导入eclipse项目到idea过程中遇到 Imported project refers to unkonwn jdks JavaSE-1.8 解决方法: file --> Project ...

  6. c语言实现基本的数据结构(三) 栈

    #include <stdio.h> #include <tchar.h> #include <stdlib.h> #define StackSize 5 #def ...

  7. DFS树求割点问题

    时间复杂度:O(n玄学)总之不大 代码实现(好麻烦,蓝题变紫题) #include<iostream> #include<string.h> #include<algor ...

  8. Linux 终端命令格式

    Linux 终端命令格式 一.目标 了解终端命令格式 知道如何查阅终端命令帮助信息 二. 终端命令格式 command [-options] [parameter] 说明: command:命令名,相 ...

  9. 《Java 8 in Action》Chapter 4:引入流

    1. 流简介 流是Java API的新成员,它允许你以声明性方式处理数据集合(通过查询语句来表达,而不是临时编写一个实现).就现在来说,你可以把它们看成遍历数据集的高级迭代器.此外,流还可以透明地并行 ...

  10. shiro登录名的获取

    登录名的获取:通过的SecurityUtils的shiro import org.apache.shiro.SecurityUtils; //登录用户名 String loginAccount = S ...