HDU 1028 HDU 1398 (母函数)】的更多相关文章

给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案?如何解决这个问题呢?考虑构造母函数.如果用x的指数表示称出的重量,则:    1个1克的砝码可以用函数1+x表示,    1个2克的砝码可以用函数1+x2表示,(x2表示x的2次方)    1个3克的砝码可以用函数1+x3表示,    1个4克的砝码可以用函数1+x4表示,(1+x)(1+x2)(1+x3…
题意:输入一个n  给出其所有组合数 如: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; 重复不算 母函数入门题: #include<iostream> #include<queue> #include<cstdio> #include<cstring> #include<vector> #include<map> #include<algo…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 就是可以用任意个1.2.3....,所以式子写出来就是这样:(1+x+x^2+...)(1+x^2+x^4+...)(1+x^3+x^6+...)...(1+x^n+x^(2*n)+...)... 因为求 x^n 系数,所以再往后的式子就没有贡献了,求到第 n 个式子即可. 一个x^2就像一条边一样,可以让第 k 项的系数转移给第 k+2 项.按这个思路写代码就行了. #include<iostr…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 整数划分,每个数可以用无限次: 所以构造 f(x) = (1+x+x2+x3+...)(1+x2+x4+...)(1+x3+x6+...)...(1+xn) 乘起来后的 xn 的系数就是方案数: 用两个数组做即可,从第一个括号开始一个一个乘,f[i] 表示此时 xi 项的系数,后面每乘过来一个括号,相当于多了一种转移,所以加上. 代码如下: #include<iostream> #include…
简单的钱币兑换问题,就是钱的种类多了一点,完全背包. #include<cstdio> #include<cstring> int main () { ]; memset(dp,,sizeof(dp)); dp[]=; ; i<=; i++) ; j++) dp[j]+=dp[j-i]; while(~scanf("%d",&i)) printf("%d\n",dp[i]); ; }…
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #define INF 1000000009 using namespace std; ; int c1[_max], c2[_max]; int main() { int n,i,j,k; while(cin>>n) { ;i<=n;i…
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstring> typedef long long LL; LL ans[][]; LL n,anss; LL get(LL x,LL y) { ) return ans[x][y]; ) ; ; ans[x][y]=; LL i; ;i<=y;i++) ans[x][y]+=get(x-y,i); re…
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. "The second problem is, given an positive integer N, we define an equation like this: N=a[1]+a[2…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目大意:3=1+1+1=1+2=3 :4=4=1+1+1+1=1+2+1=1+3:所以3有3种加法,4有4种加法,给出一个n,(1<=n<=120) ,计算n有几种加法. 解法:母函数的最简单的一道入门题之一. 说明:今早上突发奇想着想学学母函数,就搜了搜HDU ACM PPT 的母函数一版,把这道题分享给大家. 感想:这道题之前看过,推过公式什么的,没推出来.今天才知道是母函数的算法.算…
 HDU 1028 Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. &q…