hdu1028---Ignatius and the Princess III

tips:

  1.母函数蕴含的是一种映射关系

  2.(或的关系---+---分类)*()---括号间乘法对应分步法则

  3.母函数是用来展示数字序列的挂衣架

  4.ref:学堂在线组合数学

  5.模拟计算+合并同类项(指数相同)计算系数---也即方案数

//后一个多项式中的每一项去乘前一项多项式中(已计算...可能就是这里dp)的每一项
//学习中看的bolg
//学堂在线视频笔记
//https://www.cnblogs.com/hongshijie/p/7727000.html
//https://blog.csdn.net/xiaofei_it/article/details/17042651
//https://www.xuebuyuan.com/zh-tw/645971.html
//另一种母函数的详细解释
//https://blog.csdn.net/hnust_xiehonghao/article/details/7857874

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=126;
int n;
int a[M];
int b[M];
int n1[M],n2[M],v[M];
int main(){
    while(scanf("%d",&n)!=EOF){
        //memset(a,0,sizeof(a));
        fill(a,a+M,0);
        a[0]=1;
        memset(n1,0,sizeof(n1));
        //每个砝码使用次数无限
        //fill(n2,n2+M,1);
        for(int i=0;i<=n;i++){
            v[i]=i;
        }
        for(int i=1;i<=n;i++){
            memset(b,0,sizeof(b));
            for(int j=n1[i];  j*v[i] <= n;j++){
                for(int k=0;k+j*v[i]<=n;k++){
                    b[k+j*v[i]]+=a[k]*1;//合并同类项
                }
            }
            memcpy(a,b,sizeof(b));
            /*for(int kk=0;kk<=n;kk++){
                a[kk]=b[kk];
                b[kk]=0;
            }*/
        }
        printf("%d\n",a[n]);
    }
    return 0;
}
View Code

还有初九,初十,11三天的题目没补 o(╥﹏╥)oヾ(◍°∇°◍)ノ゙

posted @ 2018-08-21 17:55  SUMay  阅读(113)  评论(0编辑  收藏  举报