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. Python os、sys、pickle、json等模块

    1.os 所有和操作系统相关的内容都在os模块,一般用来操作文件系统 import os os.makedirs('dirname1/dirname2') # 可生成多层递归目录 os.removed ...

  2. [HNOI2011]括号修复

    设\(nd[4]\) 0--多出来的右括号 1--多出来的左括号 2--取反后多出来的右括号 3--取反后多出来的左括号 这样一来 Swap: swap(0,3),swap(1,2),swap(sn[ ...

  3. js-ES6学习笔记-Reflect

    1.Reflect对象与Proxy对象一样,也是 ES6 为了操作对象而提供的新 API.Reflect对象的设计目的有这样几个. 将Object对象的一些明显属于语言内部的方法(比如Object.d ...

  4. PHP 协程最简洁的讲解

    协程,又称微线程,纤程.英文名Coroutine.协程的概念很早就提出来了,但直到最近几年才在某些语言(如Lua)中得到广泛应用. 子程序,或者称为函数,在所有语言中都是层级调用,比如A调用B,B在执 ...

  5. (转)预处器的对比——Sass、LESS和Stylus

    英文原文:http://net.tutsplus.com/tutorials/html-css-techniques/sass-vs-less-vs-stylus-a-preprocessor-sho ...

  6. jquery判断浏览器的内核

    <script type='text/javascript'> $(function(){ if($.browser.msie) { alert("IE浏览器"); } ...

  7. 学习MVC之租房网站(十一)-定时任务和云存储

    学习MVC之租房网站(十一)-定时任务和云存储 在上一篇<学习MVC之租房网站(十)-预约和跟单>完成了用户的预约看房以及后台操作员对预约看房的跟单操作.接下来会做定时发邮件的功能,并且用 ...

  8. JavaScript Math对象方法

    console.log(Math.abs(123));//绝对值 console.log(Math.ceil(123.3));//向上舍入 console.log(Math.floor(123));/ ...

  9. Angular调用父Scope的函数

    app.directive('toggle', function(){ return { restrict: 'A', template: '<a ng-click="f()" ...

  10. 【转】boost库之geometry

    #include <boost/assign.hpp> #include <boost/geometry/geometry.hpp> #include <boost/ge ...