初识母函数

例1:若有1克、2 克、3克、4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案?
 
如何解决这个问题呢?考虑构造母函数。
如果用x的指数表示称出的重量,则:
1个1克的砝码可以用函数1+x表示,
1个2克的砝码可以用函数1+x2表示,
1个3克的砝码可以用函数1+x3表示,
1个4克的砝码可以用函数1+x4表示
 
(1+x)(1+x2)(1+x3)(1+x4)
=(1+x+x2+x3)(1+x3+x4+x7)
=1+x+x2+2x3+2x4+2x5+2x6+2x7+x8+x9+x10 
 
(上式中的1是代表x^0,就是重量为1的砝码一个也没拿,后面的也是这么理解的)
 
从上面的函数知道: 可称出从 1 克到 10 克,系数便是方案数。
例如右端有2x5 项,即称出5克的方案有2:5=3+2=4+1;同样,6=1+2+3=4+2;10=1+2+3+4。
故称出6克的方案有2,称出10克的方案有1 
 
2: 求用 1 分、 2 分、 3 分的邮票贴出不同数值的方案数 ——
 
n 因邮票允许重复,故母函数为: G(x) = (1 + x + x^2 + x^3....)(1 + x^2 + x^4 + x^6 + ....)(1 + x^3 + x^6 + x^9 + ...)
这个式子可以这么理解:1分的拿0,1,2,3.....个,2分的拿0,1,2,3,4....,3分的0,1,2,3,4......这样就
PS:x的指数除以某种邮票的面值,就是某次拿这种有票的个数;
 
例三 hdu
Square Coins
Problem Description
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:

ten 1-credit coins,
one 4-credit coin and six 1-credit coins,
two 4-credit coins and two 1-credit coins, and
one 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Silverland.
 

Input
The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
 

Output
For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.
 

Sample Input
            
            
2 10 30 0
 
#include <iostream>
using namespace std;
const int lmax=300;
int c1[lmax+1],c2[lmax+1];
int main(void)
{
    int n,i,j,k;
    while (cin>>n && n!=0)
     {
         for (i=0;i<=n;i++)
         { c1[i]=1; c2[i]=0; }
         for (i=2;i<=17;i++) // 17 这里有共17种 Silverland钱币,所以有17 的大括号,即17个多项式相乘; 
         {
              for (j=0;j<=n;j++)   // j 代表前面括号中的各项的指数
                for (k=0;k+j<=n;k+=i*i)   // 这里的k 代表的是当前括号中的各项的指数 k += i*i 为什么要加 i*i 呢?其实是有硬币的面值(即各种之间面值的关系,是倍数关系,
                                                           //或者是平方关系)决定的;
                    { c2[j+k]+=c1[j]; }      //  j + k //就是两个括号中的多项式相乘后的指数;
              for (j=0;j<=n;j++)
             { c1[j]=c2[j]; c2[j]=0; }
        }   
       cout<<c1[n]<<endl;
    }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值