POJ 2229 递推】的更多相关文章

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…
把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t(0 <= t <= 20).以下每行均包含二个整数M和N,以空格分开.1<=M,N<=10. Output 对输入的每组数据M和N,用一行输出相应的K. Sample Input 1 7 3 Sample Output 8 题解+代码: 1 /* 2 这道题两种做法,一种dfs,一种递推.这里用的递推法(递推法…
题意 1 12 123 1234 12345 ....这样的序列 问第n位数字是几   是数字! 1-9! 思路:递推关系 主要是位数的计算   用a[i]=a[i-1]+(int)log10((double)i)+1;   每加一个n位数  加log10(n)+1位 还有取数字    (i-1)/(int)pow((double)10,len-pos)%10   len-pos 是到最后有多少位   数字/10^(len-pos) 就把后面几位截断了再%10就能取出要的数字了 参考:https…
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…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 20315   Accepted: 7930 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…
构造,递推,因为划分是合并的逆过程,考虑怎么合并. 先把N展开成全部为N个1然后合并,因为和顺序无关,所以只和出现次数有关情况有点多并且为了避免重复,分类,C[i]表示序列中最大的数为2^i时的方案数 树形表示合并 (UVA 10562 Undraw the Trees的表示方法...7          (2^0) (7表示2^0出现的次数)_ _ _|  |  |1 2 3    (2^1) (7个1可以合并成1~3个2) _ _   |  |   1 1         (2^2) (继续…
题意 : 给出一个数 n ,问如果使用 2 的幂的和来组成这个数 n 有多少种不同的方案? 分析 :  完全背包解法 将问题抽象==>有重量分别为 2^0.2^1.2^2…2^k 的物品且每种物品可无限取,问有多少种方案来填满容量为 n 的背包? 之前并不知道背包还能用来计数....... 有一道裸的背包计数问题可以作为练习 ==> HDU 1284 定义 dp[ i ][ j ] 为前 i 种物品组成总重量 j 的方案数为多少.初始化为 dp[ 0 ][ 0 ] = 1 其他为 0 则状态转…
题目链接:http://poj.org/problem?id=1664 dp[i][j]表示i个盘放j个苹果的方案数,dp[i][j] 可以由 dp[i - 1][j] 和 dp[i][j - i] 递推而来. 当盘子的个数大于等于苹果的个数: dp[i - 1][j] :i - 1个盘子放j个苹果,说明i个盘子里最少有一个盘子是空的 dp[i][j - i] :i个盘子都放了苹果,说明有j - i个苹果是随便放置的 否则: dp[i][j] = dp[i - 1][j] 然后没有苹果的盘子的方…
Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 1738 Description A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simul…
http://poj.org/problem?id=2506 题意: 思路:递推.a[i]=a[i-1]+2*a[i-2]. 计算的时候是大整数加法.错了好久,忘记考虑1了...晕倒. #include<iostream> #include<string> #include<cstring> #include<cstdio> using namespace std; int n; ][]; void cacl(int i) { int k; ]); ]);…