POJ-2229
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+4Help 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
7Sample 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的更多相关文章
- poj 2229 【完全背包dp】【递推dp】
poj 2229 Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 21281 Accepted: 828 ...
- poj -2229 Sumsets (dp)
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组 ...
- poj 2229 一道动态规划思维题
http://poj.org/problem?id=2229 先把题目连接发上.题目的意思就是: 把n拆分为2的幂相加的形式,问有多少种拆分方法. 看了大佬的完全背包代码很久都没懂,就照着网上的写了动 ...
- poj 2229 Ultra-QuickSort(树状数组求逆序数)
题目链接:http://poj.org/problem?id=2299 题目大意:给定n个数,要求这些数构成的逆序对的个数. 可以采用归并排序,也可以使用树状数组 可以把数一个个插入到树状数组中, 每 ...
- POJ 2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 11892 Accepted: 4782 Descrip ...
- DP:Sumsets(POJ 2229)
数的集合问题 题目大意:给定你一个整数m,你只能用2的k次幂来组合这个数,问你有多少种组合方式? 这一题一看,天啦太简单了,完全背包?是不是? 不过的确这一题可以用完全背包来想,但是交题绝对是TLE ...
- poj 2229 Sumsets DP
题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...
- poj 2229 Sumsets(dp 或 数学)
Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...
- Sumsets(POJ 2229 DP)
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 15293 Accepted: 6073 Descrip ...
- poj 2229 DP
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 15326 Accepted: 6088 Descrip ...
随机推荐
- .net调用存储过程详解(转载)
本文的数据库用的是sql server 连接字符串 string conn = ConfigurationManager.ConnectionStrings["NorthwindConnec ...
- php部分:网页中报表的打印,并用CSS样式控制打印的部分;
网页中报表的打印,是通过调用window对象中的print()方法实现打印功能的: 调用浏览器本身的打印功能实现打印 <a href="#" onclick="wi ...
- 扩容数据盘_Linux
扩容数据盘_Linux_扩容云盘_云盘_用户指南_云服务器 ECS-阿里云 https://help.aliyun.com/document_detail/25452.html 磁盘扩容付费后: 在控 ...
- d[k]=eval(k)
lk = ['oid', 'timestamp', 'signals', 'area', 'building', 'city', 'name', 'floor', 'industry', 'regio ...
- viewport详解
本文主要讲解viewpor相关知识. 参考资料&内容来源 博客园:https://www.cnblogs.com/zaoa/p/8630393.html 博客园:http://www.cnbl ...
- 【题解】CF997C Sky Full of Stars
[题解]CF997C Sky Full of Stars 为什么我的容斥原理入门题是这道题????????? \(Part-1\)正向考虑 直接考虑不合法合法的方案吧 所以我们设行有\(i\),列有\ ...
- HNOI2017
本蒟蒻表示终于把$HNOI2017$全AC了... 万岁! 附上各个题的题解: $DAY1$: $T1$: BZOJ4825: [Hnoi2017]单旋 $T2$: BZOJ4826: [Hnoi20 ...
- jq实现批量图片上传
http://blog.csdn.net/lmj623565791/article/details/31513065 jq实现批量图片上传 http://blog.csdn.net/lmj623565 ...
- 时尚创意VI矢量设计模板
时尚创意VI矢量设计模板 创意VI VI设计 企业VI 时尚背景 信封设计 封面设计 杯子 桌旗 帽子 EPS矢量素材下载 http://www.huiyi8.com/vi/
- BZOJ 2021 [Usaco2010 Jan]Cheese Towers:dp + 贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i]( ...