题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description
There are four combinations of coins to pay ten credits:
ten 1-credit coins,
one 4-credit coin and six 1-credit coins,
two 4-credit coins and two 1-credit coins, and
one 9-credit coin and one 1-credit coin.
Your mission is to count the number of ways to pay a given amount using coins of Silverland.
Input
Output
Sample Input
Sample Output
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,dp[]={};
for(int i=;i<=;++i)//预处理打表
for(int j=i*i;j<;++j)
dp[j]+=dp[j-i*i];
while(cin>>n&&n){cout<<dp[n]<<endl;}
return ;
}
AC代码二之母函数(15ms):生成函数G(x)=(1+x^1+x^2+...)(1+x^4+x^8+x^12+...)(1+x^9+x^18+...)(...)(1+x^289)。
#include<bits/stdc++.h>
using namespace std;
int n,c1[],c2[];
void init(){
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
c1[]=;//指数为0的系数为1
for(int i=;i<=;++i){
for(int j=;j<=;++j)
for(int k=;k+j<=;k+=i*i)
c2[k+j]+=c1[j];
for(int j=;j<=;++j)
c1[j]=c2[j],c2[j]=;
}
}
int main(){
init();
while(~scanf("%d",&n)&&n){printf("%d\n",c1[n]);}
return ;
}
题解报告:hdu 1398 Square Coins(母函数或dp)的更多相关文章
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU 1398 Square Coins 整数拆分变形 母函数
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- HDU 1398 Square Coins(母函数或dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- hdu 1398 Square Coins 分钱币问题
Square Coins Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hdu 1398 Square Coins(生成函数,完全背包)
pid=1398">链接:hdu 1398 题意:有17种货币,面额分别为i*i(1<=i<=17),都为无限张. 给定一个值n(n<=300),求用上述货币能使价值 ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
- HDOJ 1398 Square Coins 母函数
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- 杭电ACM hdu 1398 Square Coins
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
- HDU 1398 Square Coins(DP)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
随机推荐
- Linux信号通讯编程
信号通讯流程为: ①进程A/内核选择信号 ②发送信号 ③进程B接收信号并处理 Linux系统支持的全部信号均定义在/usr/include/asm/signal.h.当中常见的信号有: ①SIGKIL ...
- Zookeeper中的FastLeaderElection选举算法简述
Zookeeper是一个开源的分布式应用协调项目, 当中为了保证各节点的协同工作,Zookeeper在工作时须要有一个Leader. 而Leader是怎样被选举出来的?Zookeep中使用的缺省算法称 ...
- cocos2dx 制作单机麻将(五)
cocos2dx 制作单机麻将(五) 麻将逻辑6 最基础的4人麻将逻辑(轮流循环出牌, 之前学的都能用上 跑起来了!!!) 最基础的麻将逻辑 依据自己须要 设置麻将人数GAME_PLAYER 基本流 ...
- DLR之 ExpandoObject和DynamicObject的使用演示样例
ExpandoObject :动态的增删一个对象的属性,在低层库(比如ORM)中非常实用.因为ExpandoObject实现了IDictionay<string, object>接口,常见 ...
- 包管理 import debug 模块管理 module
import sys, os this_file_abspath = os.path.dirname(os.path.abspath(__file__)) ProjectUtil_path = '{} ...
- Deep Learning 28:读论文“Multi Column Deep Neural Network for Traffic Sign Classification”-------MCDNN 简单理解
读这篇论文“ Multi Column Deep Neural Network for Traffic Sign Classification”是为了更加理解,论文“Multi-column Deep ...
- Golang1.8编译静态库给C使用
Go实例代码: package main import ( "fmt" ) import "C" //export Printf func Printf(for ...
- linux CANopenSocket 初试
/************************************************************************************** * linux CANo ...
- URAL2104. Game with a Strip(博弈)
There is a strip 1 × n with two sides. Each square of the strip (their total amount is 2n, n squares ...
- AutoIT: ControlSetText
1. ControlSetText :可以摆脱Send的限制,在适当的文本框位置输入用户想要输入的信息.2. ControlGetText可以获取文本 Run("notepad.exe&qu ...