Sumsets

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3968    Accepted Submission(s): 1578

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
 
Source
 
Recommend
teddy
 
分析:
划分规则:
1或者2倍数
dp[i]:i的方案数
i为奇数:肯定有一个落单的1,所以就是i-1的方法数
i为偶数:两种情况
两个1:所以就是i-2的方法数
没有1:i/2的所有方案*2就是i的方案数
 
code:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<set>
#include<map>
#include<list>
#include<algorithm>
using namespace std;
typedef long long LL;
int mon1[]= {,,,,,,,,,,,,};
int mon2[]= {,,,,,,,,,,,,};
int dir[][]={{,},{,-},{,},{-,}}; //sf???
#define max_v 1000005
LL dp[max_v];
int main()
{
dp[]=;
dp[]=;
for(int i=;i<=;i++)
{
if(i%==)
dp[i]=dp[i-]%;
else
dp[i]=(dp[i-]+dp[i/])%;
}
int x;
while(~scanf("%d",&x))
{
printf("%lld\n",dp[x]);
}
return ;
}
/*
划分规则:
1或者2倍数 dp[i]:i的方案数 i为奇数:肯定有一个落单的1,所以就是i-1的方法数
i为偶数:两种情况
两个1:所以就是i-2的方法数
没有1:i/2的所有方案*2就是i的方案数
*/

HDU 2709 Sumsets 经典简单线性dp的更多相关文章

  1. HDU 2059 龟兔赛跑(超级经典的线性DP,找合适的j,使得每个i的状态都是最好的)

    龟兔赛跑 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  2. HDU 2157 How many ways??(简单线性DP | | 矩阵快速幂)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2157 这道题目很多人的题解都是矩阵快速幂写的,矩阵快速幂倒是麻烦了许多了.先给DP的方法 dp[i][ ...

  3. HDU 2709 Sumsets(递推)

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

  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 1003 MAX SUM 简单的dp,测试样例之间输出空行

    测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...

  7. hdu 2709 Sumsets

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

  8. HDU-1260.Tickets(简单线性DP)

    本题大意:排队排票,每个人只能自己单独购买或者和后面的人一起购买,给出k个人单独购买和合买所花费的时间,让你计算出k个人总共花费的时间,然后再稍作处理就可得到答案,具体格式看题意. 本题思路:简单dp ...

  9. 简单线性dp

    小zc现在有三个字符串,他想知道前两个字符串能不能生成第三个字符串,生成规则如下:第一个串的每个字符都可以往第二个串的任意位置插入(包括首尾位置),但必须保证来源于第一个串中的字符在生成后的串中的相对 ...

随机推荐

  1. POJ3261(SummerTrainingDay10-G 后缀数组)

    Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15974   Accepted: 7041 Ca ...

  2. redis 单节点安装

    wget http://download.redis.io/releases/redis-5.0.3.tar.gz 1.下载解压 2.make编译 3.提示没有安装安装gcc,安装gcc yum in ...

  3. git 报错:error: failed to push some refs to 'https://github.com/Anderson-An/******.git'(已解决)

    提交push 报错: $ git push origin masterTo https://github.com/Anderson-An/******.git ! [rejected] master ...

  4. javascript: 数组详细操作方法及解析合集(9个改变8个不变12个遍历)

    改变原数组的方法(9个): 1 2 3 4 5 let a = [1,2,3]; ES5: a.pop()/ a.shift()/ a.push()/ a.unshift()/ a.reverse() ...

  5. 【读书笔记】iOS-网络-HTTP-URL百分号编码

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, ty ...

  6. jQuery复选框全选和全选取消

    jQuery(".salaryIds").each(function(){ if(jQuery("#salaryIds").attr("checked ...

  7. postman获取全局

    1.获取token接口时,在test里面输入如下语句 postman.clearGlobalVariable("token"); var jsonData = JSON.parse ...

  8. [Objective-C] id类型和instancetype类型

    前些时间在源码里看到instancetype返回类型,一脸惊异,表示接触iOS不久没见过这东西,但发现跟id功能差不多.故查了一些资料,了解了两者之间的区别,故将资料简单翻译整理了一下,为博客充一个数 ...

  9. java 版本压缩、解压缩zip

    import java.io.*; import java.util.*; import java.util.zip.ZipOutputStream; import java.util.zip.Zip ...

  10. ubuntu安装python-ldap模块

    模块 一直很头疼好多依赖的模块 今天安装一个python-ldap  和ldap交互的模块 首先安装的时候会提示我们 compilation terminated. error: command 'x ...