完全背包.. --------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #defi…
题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 617  Solved: 344[Submit][Status] Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1677 题意: 给定n(n <= 10^6),将n分解为2的幂次方之和,问你有多少种方法. 题解: 两种方法. 一.无限背包 将1,2,4,8...看作物品体积就好. 复杂度O(n*k),k约为20. 二.递推 对于dp[i],有两种情况. (1)i为奇数.则分解结果中一定有1. 所以dp[i] = dp[i-1]. (2)i为偶数.再分两种情况: a. 分解结果中有1,所以dp[i] +…
设f[i]为i的方案数,f[1]=1,考虑转移,如果是奇数,那么就是f[i]=f[i-1]因为这1一定要加:否则f[i]=f[i-1]+f[i>>1],就是上一位+1或者i/2位所有因子乘二 #include<iostream> #include<cstdio> using namespace std; int n,f[1000005]; int main() { scanf("%d",&n); f[1]=1; for(int i=2;i&l…
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 626  Solved: 348[Submit][Status] Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers th…
http://www.lydsy.com/JudgeOnline/problem.php?id=1677 完全背包很容易想到,将1,2,4...等作为物品容量即可. 然后这题还有一个递推式 f[i]==f[i-1], 当i%2==1 f[i]==f[i-1]+f[i/2], 当i%2==0 当i为奇数时,我们可以看为i-1加上一个1的情况,那么只有f[i-1]中情况(因为每种情况只是多了一个1) 当i为偶数时,分为2种情况,含有1和不含有1,当含有1时,那么情况就是f[i-1],当不含有1时,情…
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 570  Solved: 310[Submit][Status] Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers th…
... #include <iostream> using namespace std; ]; int n,i; int main() { cin>>n; f[]=; ;i<=n;i++) { f[i]=f[i-]; )) f[i]+=f[i/]; f[i]%=; } cout<<f[n]; ; } Description Farmer John commanded his cows to search for different sets of numbers…
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+…
一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code ----------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<i…