POJ-2229 Sumsets---完全背包变形】的更多相关文章

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)…
poj 2229 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 21281   Accepted: 8281 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…
discuss 看到有人讲完全背包可以过, 假如我自己做的话, 也只能想到完全背包了 思路: 1. 当 n 为奇数时, f[n] = f[n-1], 因为只需在所有的序列前添加一个 1 即可, 所有的序列同时延迟 1 位, 不会出现重复 若是这个 1 和其他的1组成 2 而不是放在首位, 怎么办? 不会这样, 因为这个序列肯定已经存在了 证明, 假设sum(s1) = 2*k, s1内部某个1加1得到 s2, 则 sum(s2) = 2*k+1, s2 的首位仍然肯定是1, 那么 s2 也可以通…
http://poj.org/problem?id=2229 题意很简单就是给你一个数n,然后选2的整数幂之和去组成这个数.问你不同方案数之和是多少? n很大,所以输出后9位即可. dp[i] 表示组成i的不同方案数,那么 dp[1]=1;dp[2]=2; if(i%2) dp[i]=dp[i-1] ;  i如果是奇数,那么只能在i-1的每个方案数前面加上1得到i,所以方案数相等. else dp[i]=dp[i-1]+dp[i/2] ;  i如果是偶数,一种可能是i有两个1,在i-1的每个方案…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 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 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 400000/200000K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 3 Problem Description Farmer John commanded his cows to search for different sets of numbers that sum to a g…
Q: 如何判断几件物品能否被 2 辆车一次拉走? A: DP 问题. 先 dp 求解第一辆车能够装下的最大的重量, 然后计算剩下的重量之和是否小于第二辆车的 capacity, 若小于, 这 OK. Description Emma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping…
题意 : 给出一个数 n ,问如果使用 2 的幂的和来组成这个数 n 有多少种不同的方案? 分析 :  完全背包解法 将问题抽象==>有重量分别为 2^0.2^1.2^2…2^k 的物品且每种物品可无限取,问有多少种方案来填满容量为 n 的背包? 之前并不知道背包还能用来计数....... 有一道裸的背包计数问题可以作为练习 ==> HDU 1284 定义 dp[ i ][ j ] 为前 i 种物品组成总重量 j 的方案数为多少.初始化为 dp[ 0 ][ 0 ] = 1 其他为 0 则状态转…
题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+4,共有5个 思路:当N为奇数时,N的式子中都必有1,故知只需在N-1的式子中都+1就可以,即d[N] = d[N-1] 当N为偶数时,N的式子可以分为,有1 或者 没1:有1的式子,必有2个1,那么可以由N-2的式子加上两个1: 没有1的式子,把式子中的加数都除以2,故可以由N/2的式子求得. AC代码:…
Description Farmer John commanded his cows to search . Here are the possible sets of numbers that sum to : ) ++++++ ) +++++ ) ++++ ) +++ ) +++ ) ++ Help FJ count all possible representations <= N <= ,,). Input A single line with a single integer, N.…