HDU 1284 钱币兑换问题 母函数、DP
题目链接:HDU 1284 钱币兑换问题
钱币兑换问题
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5467 Accepted Submission(s): 3123
2934
12553
718831
13137761
pid=2159" style="color:rgb(26,92,200); text-decoration:none">2159
pid=1248" style="color:rgb(26,92,200); text-decoration:none">1248
pid=1203" style="color:rgb(26,92,200); text-decoration:none">1203
1231 1249思路1:母函数思想,求系数
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; #define maxn 32770
int n, c1[maxn], c2[maxn];
void Init()
{
for(int i = 0; i <= maxn; i++)
{
c1[i] = 1;
c2[i] = 0;
}
for(int i = 2; i <= 3; i++)
{
for(int j = 0; j <= maxn; j++)
for(int k = 0; k+j <= maxn; k+=i)
c2[j+k] += c1[j];
for(int j = 0; j <= maxn; j++)
{
c1[j] = c2[j];
c2[j] = 0;
}
}
}
int main()
{
Init();
while(~scanf("%d", &n))
printf("%d\n", c1[n]);
return 0;
}
思路2:DP,后面的钱能够由前面的钱推出。
代码:
#include <iostream>
#include <cstdio>
using namespace std; #define maxn 32770
int n, dp[maxn];
void Init()
{
dp[0] = 1;
for(int i = 1; i <= 3; i++)
for(int j = i; j <= maxn; j++)
dp[j] += dp[j-i];
}
int main()
{
Init();
while(~scanf("%d", &n))
printf("%d\n", dp[n]);
return 0;
}
HDU 1284 钱币兑换问题 母函数、DP的更多相关文章
- HDU 1284(钱币兑换 背包/母函数)
与 HDU 1028 相似的题目. 方法一:完全背包. 限制条件:硬币总值不超过 n. 目标:求出组合种数. 令 dp[ i ][ j ] == x 表示用前 i 种硬币组合价值为 j 的钱共 x 种 ...
- HDU 1284 钱币兑换问题 (dp)
题目链接 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. Input 每行只有一个正整数N,N小于327 ...
- HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包)
HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包) 题意分析 裸的完全背包问题 代码总览 #include <iostream> #include <cstdio> ...
- HDU 1284 钱币兑换问题(全然背包:入门题)
HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N ( ...
- HDU 1284 钱币兑换问题(普通型 数量无限的母函数)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1284 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1284 钱币兑换问题 (递推 || DP || 母函数)
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1284 钱币兑换问题 完全背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 递推公式:dp[i] = sum(dp[i], dp[i-C]) /* 钱币兑换问题 Time ...
- HDU 1284 钱币兑换问题 (动态规划 背包方案数)
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU 1284 钱币兑换问题 (完全背包)
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
随机推荐
- Day 3 EX 购物车自写
# -*- coding: utf_8 _*_# Author:Vi import copygoods = [0,[1,'iphone',20],[2,'ipad',2500]]salary = in ...
- 怎样从Cortex-m向STM32移植使用SPI接口协议
/*************************************************************************************************** ...
- jquery init 关系
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/st ...
- jQuery03
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- local-语言切换监听事件
今天在更改时钟的问题的时候,需要监听语言切换来刷新时钟的显示.记录下监听方法 //注册监听事件 intentFilter.addAction(Intent.ACTION_LOCALE_CHANGED) ...
- 71.sscanf数据挖掘
数据挖掘 sscanf(str, "%d %s %s %d %d %s %s %s", &ph[i].id, ph[i].name, ph[i].sex, &ph[ ...
- Java 批量修改文件后缀
import java.io.*; public class test { public void reName(String path, String from, String to) { File ...
- TypeScript深入学习
基础类型booleannumberstringstring[]//Array<string> 数组类型(ReadonlyArray<string>数组不能修改,也不允许被赋值给 ...
- git还原文件
http://jingyan.baidu.com/album/e4511cf33479812b855eaf67.html
- Detecting a return-oriented programming exploit
A method and apparatus for detecting a Return-Oriented Programming exploitation. At a computer devic ...