Sumsets

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1996    Accepted Submission(s): 786

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
 

/*
题意:给出一个整数n,求解该整数n有多少种由2的幂次之和组成的方案.
解题思路:
1.可以将n用二进制表示.
n=1,只有1种表示方法。
n=2,10(2),二进制表示下,可以分拆成{1,1},{10}有两种表示方法
n=3, 11(2),可以分拆成{1,1,1},{10,1}.
n=4, 100(2),{1,1,1,1},{10,1,1},{10,10},{100}.
总结:如果所求的n为奇数,那么所求的分解结果中必含有1,
因此,直接将n-1的分拆结果中添加一个1即可 为s[n-1]
如果所求的n为偶数,那么n的分解结果分两种情况
1.含有1 这种情况可以直接在n-1的分解结果中添加一个1即可 s[n-1]
2.不含有1 那么,分解因子的都是偶数,将每个分解的因子都除以2,
刚好是n/2的分解结果,并且可以与之一一对应,这种情况有 s[n/2] */
/*#include<stdio.h>
#include<string.h>
int a[1000010];
int main()
{
a[1]=1;
a[2]=2;
int n,i=3;
while(i<=1000000)
{
a[i++]=a[i-1];
a[i++]=(a[i-1]+a[i>>1])%1000000000;
}
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",a[n]);
}
return 0;
}*/
#include<stdio.h>
#include<string.h>
int f[1000010];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(f,0,sizeof(f));
f[1]=1;
for(int i=2;i<=n;i++)
{
if(i&1)
f[i]=f[i-1];
else
f[i]=(f[i-1]+f[i>>1])%1000000000;
}
printf("%d\n",f[n]);
}
return 0;
}

hdoj--2709--Sumsets(数位dp)的更多相关文章

  1. hdoj 3555 BOMB(数位dp)

    //hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...

  2. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

  3. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  4. bzoj1026数位dp

    基础的数位dp 但是ce了一发,(abs难道不是cmath里的吗?改成bits/stdc++.h就过了) #include <bits/stdc++.h> using namespace ...

  5. uva12063数位dp

    辣鸡军训毁我青春!!! 因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题 于是在猫大的帮助下我发现这道习题是数位dp 然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试 果然 ...

  6. HDU2089 不要62[数位DP]

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. 数位DP GYM 100827 E Hill Number

    题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...

  8. 数位dp总结

    由简单到稍微难点. 从网上搜了10到数位dp的题目,有几道还是很难想到的,前几道基本都是模板题,供入门用. 点开即可看题解. hdu3555 Bomb hdu3652 B-number hdu2089 ...

  9. 数位DP入门

    HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...

  10. 数位DP之奥义

    恩是的没错数位DP的奥义就是一个简练的dfs模板 int dfs(int position, int condition, bool boundary) { ) return (condition ? ...

随机推荐

  1. Reentrant protected mode kernel using virtual 8086 mode interrupt service routines

    A method for allowing a protected mode kernel to service, in virtual 8086 mode, hardware interrupts ...

  2. POJ-1785-Binary Search Heap Construction(笛卡尔树)

    Description Read the statement of problem G for the definitions concerning trees. In the following w ...

  3. Collection 和 Collections 的差别?

    Collection 是 java.util 下的接口,它是各种集合的父接口,继承于它的 接口主要有 Set 和 List:Collections 是个 java.util 下的类.是针对集合的 帮助 ...

  4. LA 6437 Power Plant (prim最小生成树)

    还是裸的最小生成树 #include<bits/stdc++.h> using namespace std; int T,N,M,P,K,a,b,c; int dist[1020],m[1 ...

  5. java大数类,两个不超过20位都不为0的十进制字符串相乘,华为笔试题

    import java.math.BigInteger; import java.util.*; import java.io.*; public class Main { public static ...

  6. ubuntu16.04安装opencl

    参考链接:https://www.jianshu.com/p/ad808584ce26 安装OpenCL OpenCL是一系列库和头文件,需要根据硬件安装对应的SDK,也就是说,如果希望使用Intel ...

  7. Linux就该这么学 20181007第十章Apache)

    参考链接https://www.linuxprobe.com/ /etc/httpd/conf/httpd.conf 主配置文件 SElinux域 ---服务功能的限制 SElinux安全上下文 -- ...

  8. ASP.NET MVC 使用FluentScheduler做定时任务

    源代码地址: https://github.com/fluentscheduler/FluentScheduler 使用NuGet安装FluentScheduler 这是我实际项目中用到的代码,也可看 ...

  9. 好久不见我又回来了cnblogs

    最近一直没时间写博客.... 最近工作中遇到的问题,当时花费了一定功夫才解决. 当再次遇到,同样问题的时候,我知道自己能够解决的,但是却同样,要走原来的弯路解决他. 说到底还时确实总结啊.大概是没时间 ...

  10. 3ds Max实例教程-顽皮的小孩

    本教程介绍使用3ds Max制作设计一个顽皮的小孩,这个作品的灵感来源于作者的亲身经历,也是以真实人物为原型做出来这么一个小人. 作者: Claudius Vesting 使用软件:3ds Max,P ...