HDU 1398 Square Coins 母函数

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

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

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\n",c1[n]);
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/rolight/p/3896432.html

你可能感兴趣的:(HDU 1398 Square Coins 母函数)