zoukankan      html  css  js  c++  java
  • HDU 1398 Square Coins 母函数

    就是经典的找零钱问题的小小变形,DP和母函数都可搞

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <string>
    #include <iostream>
    #include <map>
    #include <cstdlib>
    #include <list>
    #include <set>
    #include <queue>
    #include <stack>
    
    using namespace std;
    
    typedef long long LL;
    const int maxn = 500;
    int c1[maxn],c2[maxn];
    
    int main() {
        int n; 
        while(scanf("%d",&n),n) {
            for(int i = 0;i <= n;i++) {
                c1[i] = 1; c2[i] = 0;
            }
            for(int i = 2;i * i <= n;i++) {
                int nowval = i * i;
                for(int j = 0;j <= n;j += nowval) {
                    for(int k = 0;k + j <= n;k++) {
                        c2[j + k] += c1[k];
                    }
                }
                memcpy(c1,c2,sizeof(c1));
                memset(c2,0,sizeof(c2));
            }
            printf("%d
    ",c1[n]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Poj2033
    CodeForces 540
    CodeForces 548
    LeetCode#2 Add Two Numbers
    CodeForces 544A
    POJ 2431Expedition
    HLG1116-选美大赛
    清华学堂 列车调度(Train)
    清华学堂 LightHouse
    清华学堂 Range
  • 原文地址:https://www.cnblogs.com/rolight/p/3896432.html
Copyright © 2011-2022 走看看