POJ2229 - Sumsets(完全背包)】的更多相关文章

题目大意 给定一个数N,问由不同的2的幂之和能组成N的方法有多少种 题解 看完题目立马想到完全背包...敲完代码上去超时了....后来发现是%的原因...改成减法就A了...%也太他妈耗时了吧!!!(还有一种O(n)的算法...) 代码: #include<stdio.h> #include<string.h> #define MOD 1000000000 #define MAXN 1000005 int dp[MAXN]; int main() { int n; scanf(&q…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 19024   Accepted: 7431 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…
题目链接: https://vjudge.net/problem/POJ-2229 题目大意: 给定一个N,只允许使用2的幂次数,问有多少种不同的方案组成N. 思路: 处理出2的幂次方的所有的数字,当做物品,每个物品次数不限,求凑出体积为N的方案数 类似完全背包,先枚举物品,再正序枚举体积,转移状态dp[i][j]表示前i件物品凑出的体积为j的方案数 dp[i][j] = dp[i - 1][j] + dp[i - 1][j - w[i]] #include<iostream> #includ…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 13210   Accepted: 5300 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…
Sumsets 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)…
挑战DP 题意: 被组合数只能是2的整数幂,然后给出一个数问有多少种组合(mod1e10): 思路: 完全背包做啊-还是蛮简单的-(这里取膜要改成加法,省时间-) dp[i]代表对于j的方案数 贴一发吧- #include <iostream> #include <cstdio> #include <string.h> #include <stack> #include <queue> #include <map> #include…
http://poj.org/problem?id=2229 分析: 显然的递推 若n为奇数,那么肯定是在n-1的基础上前面每个数+1,即f[n]=f[n-1] 若n为偶数 当第一位数字是1的时候,等同于f[n-1] 当第一位数字不是1的时候,因为都是2的倍数,可以提出一个2来,即与f[n/2]相同 综上,n为偶数时候,f[n]=f[n-1]+f[n/2]…
http://poj.org/problem?id=2229 看到题目能感觉到多半是动态规划,但是没有清晰的思路. 打表找规律: #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<map> #include<set> #define…
POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个数中的一个. 思路 最显而易见的是使用二维数组动态规划计算. 比如dp[i][j]表示以第i行j列的位置作为终点的路线的最大权值. (注意区分初始化时的意义) 那么dp[i][j]的最大值取决于dp[i-1][j-1]和dp[i-1][j],从这两者之间筛选出最大值,加到dp[i][j]上,即为dp…
Sumsets 直接翻译了 Descriptions Farmer John 让奶牛们找一些数加起来等于一个给出的数N.但是奶牛们只会用2的整数幂.下面是凑出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 帮助FJ找到 N的分配数 (1 <= N <= 1,000,000). Input N Output 排列方式总数.由于这个数可能很大,只需要保留最后9位 Sample Inpu…