题意:

  有17种硬币,每种的面值为编号的平方,比如 1,4,9,16....。给出一个数字,求组成这个面值有多少种组法?

思路:

  用普通母函数解,主要做的就是模拟乘法,因为硬币是无限的,所以每个构造式中每一个项的系数都是1。我们只需要第n项的系数,大于n的并不需要,所以大于n的项就不用再做计算了。

 #include <bits/stdc++.h>
using namespace std;
const int N=;
int main()
{
freopen("input.txt", "r", stdin);
int n, ans[N]={};
while(scanf("%d",&n), n)
{
for(int i=; i<=n; i++) ans[i]=; //初始化为1,最小面值是1
int tmp[N]={}; //保存临时的结果
for(int i=; i<&&n>=i*i; i++)
{
for(int j=; j<=n; j++)
{
for(int k=; j+k<=n; k+=i*i)
tmp[j+k]+=ans[j];
}
memcpy(ans,tmp,sizeof(tmp)); //以ans作为结果来乘
memset(tmp,,sizeof(tmp)); //置零
}
cout<<ans[n]<<endl;
}
return ;
}

AC代码

HDU 1398 Square Coins 平方硬币 (普通母函数,水)的更多相关文章

  1. HDU 1398 Square Coins 整数拆分变形 母函数

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  2. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  3. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. hdu 1398 Square Coins 分钱币问题

    Square Coins Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  6. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  7. hdu 1398 Square Coins(生成函数,完全背包)

    pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...

  8. 杭电ACM hdu 1398 Square Coins

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  9. HDU 1398 Square Coins(DP)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

随机推荐

  1. UnicodeEncodeError: 'ascii' codec can't encode character u'\u5929' in position 2: ordinal not in range(128)

    UnicodeEncodeError: 'ascii' codec can't encode character u'\u5929' in position 2: ordinal not in ran ...

  2. Broken robot

    题意: 要在$nm$的矩阵中从 $(i,j)$ 处移动到第 $n$ 行,每次移动可在不动.左移一格.右移一格.下移一格 4 种选择中等概率随机选一种,但移动不能超出矩阵.求移动次数的期望,最少保留4位 ...

  3. 09.客户端集成IdentityServer

    09.客户端集成IdentityServer 新建API的项目 dotnet new webapi --name ClientCredentialApi 在我们上一节课的代码IdentityServe ...

  4. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs&qu ...

  5. 聊聊Java里常用的并发集合

    前言 在我们的程序开发过程中,如果涉及到多线程环境,那么对于集合框架的使用就必须更加谨慎了,因为大部分的集合类在不施加额外控制的情况下直接在并发环境中直接使用可能会出现数据不一致的问题,所以为了解决这 ...

  6. 优化jQuery选择器

    优化jQuery选择器 选择优化比以前更加重要,因为越来越多的浏览器实现了queryselectorall()并承担了将jQuery选择器转移到浏览器的责任.记住这些小技巧可以让你轻松突破学习选择器时 ...

  7. HDU1829【种类并查集】

    题意: 检验给出条件是否有同性恋. 思路: 条件并查集. 还是一个类似的前缀和,sum[x]是x到根这段路径上的和,根一定是坐标越小的, 那么如果说对于同类(同一个集合)的判断就sum[a]是否等于s ...

  8. spring boot 使用Schedule创建轻量级定时任务

    Scheduled SpringBoot配置定时任务可以直接使用自带的Scheduled,这相当于一个轻量级的Quartz,它可以让我们直接使用注解来完成定时任务的配置. Scheduled调度时间设 ...

  9. SQL必知必会03 计算字段 获取当前日期时间 日期时间格式化

  10. 小程序video置顶

    page { overflow-y: none; height: 100vh; } .page__hd_media { position: fixed; width:100vw; top:; heig ...