Sumsets
Time Limit: 2000MS   Memory Limit: 200000K
Total Submissions: 19599   Accepted: 7651

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

题意:
给出一个整数n,求n有多少种由2的幂次之和组成的方案.

当n为奇数的时候,那么所求的和式中必有1,则dp[n]==dp[n-1];

当n为偶数的时候,可以分两种情况:

1.含有1,个数==dp[n-1];

2.不含有1,这时每个分解因子都是偶数,将所有分解因子都除以二,所得的结果刚好是n/2的分解结果,并且一一对应,则个数为dp[n/2];

AC代码:

 //#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std; const long long MOD=; int dp[]; int main(){
ios::sync_with_stdio(false);
int n;
while(cin>>n&&n){
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<=n;i++){
if(i&){
dp[i]=dp[i-];
}
else{
dp[i]=(dp[i-]+dp[i>>])%MOD;
}
}
cout<<dp[n]<<endl;
}
return ;
}

POJ-2229的更多相关文章

  1. poj 2229 【完全背包dp】【递推dp】

    poj 2229 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 21281   Accepted: 828 ...

  2. poj -2229 Sumsets (dp)

    http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...

  3. poj 2229 一道动态规划思维题

    http://poj.org/problem?id=2229 先把题目连接发上.题目的意思就是: 把n拆分为2的幂相加的形式,问有多少种拆分方法. 看了大佬的完全背包代码很久都没懂,就照着网上的写了动 ...

  4. poj 2229 Ultra-QuickSort(树状数组求逆序数)

    题目链接:http://poj.org/problem?id=2299 题目大意:给定n个数,要求这些数构成的逆序对的个数. 可以采用归并排序,也可以使用树状数组 可以把数一个个插入到树状数组中, 每 ...

  5. POJ 2229 Sumsets

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 Descrip ...

  6. DP:Sumsets(POJ 2229)

     数的集合问题 题目大意:给定你一个整数m,你只能用2的k次幂来组合这个数,问你有多少种组合方式? 这一题一看,天啦太简单了,完全背包?是不是? 不过的确这一题可以用完全背包来想,但是交题绝对是TLE ...

  7. poj 2229 Sumsets DP

    题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...

  8. poj 2229 Sumsets(dp 或 数学)

    Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...

  9. Sumsets(POJ 2229 DP)

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 15293   Accepted: 6073 Descrip ...

  10. poj 2229 DP

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 15326   Accepted: 6088 Descrip ...

随机推荐

  1. python 基础 6.2 raise 关键字使用

    一. raise 关键字    raise 用来触发异常    语法如下:     raise[Exception [,args [,traceback]]]     语句中Exception 是异常 ...

  2. spirng boot资料

    这里有个srping boot 各种整合的资料 https://blog.csdn.net/Winter_chen001/article/details/80537829 SpringBoot入门总结 ...

  3. web无插件播放RTSP摄像机方案,拒绝插件,拥抱H5!

    本文转自:http://www.cnblogs.com/babosa/p/7355468.html 需求 问题:有没有flash播放RTSP的播放器?H5能不能支持RTSP播放? 答案:没见过,以后估 ...

  4. ios Symbol(s) not found for architecture arm64总结 含隐藏错误cocoapods

    一.通用 报错:Desktop/project/ASDF/WEIXIN/libWeChatSDK.a (3 slices) Undefinedsymbols for architecture arm6 ...

  5. Go 语言中的数组是一种 值类型(不像 C/C++ 中是指向首元素的指针)

    the-way-to-go_ZH_CN/07.1.md at master · Unknwon/the-way-to-go_ZH_CN https://github.com/Unknwon/the-w ...

  6. MongoDB入门学习(三):MongoDB的增删查改

            对于我们这样的菜鸟来说,最重要的不是数据库的管理,也不是数据库的性能,更不是数据库的扩展,而是怎么用好这款数据库,也就是一个数据库提供的最核心的功能,增删查改.         由于M ...

  7. maven-appfuse配备步骤

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/qiaqia609/article/details/36231851 maven-appfuse配置步 ...

  8. PHP加Nginx实现动态裁剪图片方案

    许久以前写过一篇也是关于高性能PHP图片动态裁剪方案的文章,那文章使用的是nginx Cache和rewrite实现的,当然再加上CDN,那个方案存在一个问题就是图片并没有实际生成,而是以二进制的形式 ...

  9. ruby 字符串

    字符串处理函数 1.返回字符串的长度 str.length => integer 2.判断字符串中是否包含另一个串 str.include? other_str => true or fa ...

  10. vue-cookies、极验滑动验证geetest、vue-router的导航守卫

    一 . vue-cookies 参考文档简书:https://www.jianshu.com/p/535b53989b39 参考文档npm:https://www.npmjs.com/package/ ...