• HDU 2069 Coin Change (母函数)


    问题描述:找硬币问题,有个限制条件,就是总数不能超过100。   思路:将母函数变形,加一维表示数量。   代码:  
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #define MID(x,y) ((x+y)>>1)
    using namespace std;
    typedef long long LL;
    int a[5] = {1, 5, 10, 25, 50};
    /* generating_function */
    const int N = 300;
    struct generating_function{
        int c1[N][101], c2[N][101];
        int maxn;
        void init(int n){
            memset(c1, 0, sizeof(c1));
            memset(c2, 0, sizeof(c2));
            c1[0][0] = 1;
            maxn = n;
        }
        void cal(int p);
    }ef;
    void generating_function::cal(int p){
        int tmp[N][101];
        memset(tmp, 0, sizeof(tmp));
        for (int i = 0; i <= maxn; i ++){
            for (int j = 0; j <= maxn; j += a[p]){
                int k1 = j/a[p];
                if (i + j <= maxn && c2[j][k1])
                    for (int k2 = 0; k1+k2 <= 100; k2 ++)
                        tmp[i+j][k1+k2] += c1[i][k2] * c2[j][k1];
            }
        }
        memset(c1, 0, sizeof(c1));
        for (int i = 0; i <= maxn; i ++){
            for (int k = 0; k <= 100; k ++){
                c1[i][k] = tmp[i][k];
            }
        }
        return ;
    }
    int main(){
        int n;
        while(scanf("%d", &n) == 1){
            ef.init(n);
            for (int i = 0; i < 5; i ++){
                memset(ef.c2, 0, sizeof(ef.c2));
                for (int j = 0; j <= n; j += a[i]){
                    ef.c2[j][j/a[i]] = 1;
                }
                ef.cal(i);
            }
    
            int res = 0;
            for (int k = 0; k <= 100; k ++){
                res += ef.c1[n][k];
            }
            printf("%d\n", res);
        }
    	return 0;
    }
    
     
    举杯独醉,饮罢飞雪,茫然又一年岁。 ------AbandonZHANG
  • 相关阅读:
    ShaderLab 枚举常量
    PHP to .NET Compiler
    填充圆算法
    战争迷雾
    A*
    寻路算法
    Unity中将动画片段保存为文件
    令人蛋疼的错误提示 0xcdcdcdcd ,0xdddddddd ,0xfeeefeee ,0xcccccccc ,0xabababab
    2D光照
    Rider 2018 激活码
  • 原文地址:https://www.cnblogs.com/AbandonZHANG/p/4114007.html
Copyright © 2020-2023  润新知