Sumsets
Time Limit: 2000MS   Memory Limit: 200000K
Total Submissions: 16876   Accepted: 6678

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
初学动态规划,我用了一种非常愚蠢的解法耗内存又超时了...
AC代码:
#include<iostream>
#include<algorithm>
using namespace std;
int dp[+];
/*const int N_MAX = 1000000;
int dp[21][N_MAX + 1];
int main() {
int N;
while (cin >> N) {
int k = 0;
while ((1 << k) <= N) {//求使得2^k大于N的最小k
k++;
} for (int i = 0;i < k;i++)
dp[i][0] = 0;
for (int i = 1;i <= N;i++)
dp[0][i] = 1;
for (int i = 1;i < k;i++) {
for (int j = 1;j <= N;j++) {
dp[i][j] = dp[i - 1][j];
for (int k1 = 1;(j - k1*(1 << i))>=0;k1++) {
dp[i][j] += dp[i - 1][j - k1*(1 << i)];
}
}
}
cout << dp[k-1][N] << endl;
}
return 0;
}*/
//若i为奇数,(i-1)为偶数,i的组合数就是(i-1)的组合数,因为(i-1)只能加1得到i。若i为偶数,(i-1)为奇数,则通过(i-1)+1的方式得到i的组合必定带有1,接下来考虑
//全是偶数的组合数,考虑到全是偶数的组合数和(i/2)的组合数一样,因为只要(i/2)的组合数里每一个数*2就可以得到i
int main() {
int N;
while (cin >> N) {
dp[] = ;
for (int i = ;i <= N;i++) {
if ((i & )==) {//若为偶数
dp[i] = dp[i / ];
}
dp[i] += dp[i - ];
dp[i] %= ;
}
cout << dp[N] << endl;
}
return ;
}

poj 2220 Sumsets的更多相关文章

  1. POJ 2229 Sumsets

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

  2. poj -2229 Sumsets (dp)

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

  3. POJ 2549 Sumsets

    Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10593   Accepted: 2890 Descript ...

  4. poj 2459 Sumsets

    Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11612   Accepted: 3189 Descript ...

  5. poj 2229 Sumsets(dp)

    Sumsets Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 400000/200000K (Java/Other) Total Sub ...

  6. poj 2229 Sumsets 完全背包求方案总数

    Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum ...

  7. POJ 2549 Sumsets(折半枚举+二分)

    Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11946   Accepted: 3299 Descript ...

  8. POJ 2549 Sumsets hash值及下标

    题目大意:找到几何中的4个数字使他们能够组成 a+b+c=d , 得到最大的d值 我们很容易想到a+b = d-c 那么将所有a+b的值存入hash表中,然后查找能否在表中找到这样的d-c的值即可 因 ...

  9. poj 2229 Sumsets DP

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

随机推荐

  1. Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...

  2. hihocoder #1223 : 不等式 水题

    #1223 : 不等式 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/1223 ...

  3. iOS开发——UI_swift篇&TableView自定义聊天界面

    TableView自定义聊天界面   1,下面是一个放微信聊天界面的消息展示列表,实现的功能有: (1)消息可以是文本消息也可以是图片消息 (2)消息背景为气泡状图片,同时消息气泡可根据内容自适应大小 ...

  4. Hive中数据的加载和导出

    原文:http://blog.javachen.com/2014/06/09/hive-data-manipulation-language.html 关于 Hive DML 语法,你可以参考 apa ...

  5. java6内置JS引擎初接触

    本文系转载 原文地址:http://blog.csdn.net/sdyy321/article/details/6959199 由于要用到该技术,所以写了几个测试,直接上代码. 定义外部资源E:/Sc ...

  6. Scheme中一些函数在C++里面的实现与吐槽

          最终我失败了,这是显而意见,我试图在一个很看重类型是什么的语言中实现无类型操作,事实上,哪怕我实现了基本的cons,car,cdr,list后面的代码也无法写下去.比如说list-n,根据 ...

  7. How to update FVDI Commander driver to latest V2015.6.2

    As FVDI Commander products are upgraded to new versions, I often receive emails from customers askin ...

  8. python(7)– 类的反射

    python中的反射功能是由以下四个内置函数提供:hasattr.getattr.setattr.delattr,改四个函数分别用于对对象内部执行:检查是否含有某成员.获取成员.设置成员.删除成员. ...

  9. 使用openoffice将word文件转换为pdf格式遇到问题:The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from required

    The type com.sun.star.lang.XEventListener cannot be resolved. It is indirectly referenced from requi ...

  10. Spring 循环引用(singleton与prototype初始化的区别)

    原文链接请参见:http://blog.csdn.net/u010723709/article/details/47185959