hdu 2069 Coin Change (dp )

dp

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int op[10]={1,5,10,25,50};
int dp[300][300];
void fun()
{
    int i,j,k;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(j=0;j<5;j++)
    {
        for(i=1;i<=100;i++)
        {
            for(k=op[j];k<=250;k++)
            {
                dp[i][k]+=dp[i-1][k-op[j]];
            }
        }
    }
}
int main()
{
    int n;
    int i,j,k;
    fun();
    /*for(i=0;i<=20;i++)
    {
        printf("%d %d\n",i,dp[2][i]);
    }*/
    while(scanf("%d",&n)!=EOF)
    {
       int ret=0;
       for(i=0;i<=100;i++)
       {
           ret+=dp[i][n];
       }
       printf("%d\n",ret);
    }
    return 0;
}
时间: 2024-11-01 09:30:02

hdu 2069 Coin Change (dp )的相关文章

UVa 674 &amp; hdu 2069 Coin Change (母函数,dp)

链接:uva 674 题意:有5中货币,价值分别为 50-cent, 25-cent, 10-cent, 5-cent,1-cent,数量都为无限个, 给定一个数 n,求用上述货币组成价值为 n 的方法有多少? 分析:因为n<=7489,可以用 母函数 或 dp 打表 对于dp状态方程为: dp[j]+=dp[j-c[i]] 母函数: #include<stdio.h> int c1[7500],c2[7500],w[5]={1,5,10,25,50};; void mhs() { in

HDU 2069 Coin Change (经典DP)

Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14500    Accepted Submission(s): 4879 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1

hdu 2069 Coin Change(完全背包)

Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16592 Accepted Submission(s): 5656 Problem Description Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent.

UVA 674 Coin Change (DP)

Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money. For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent c

HDU 4745 Two Rabbits(DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意:n个数排成一个环.两个人AB初始时各自选定一个位置.每一轮A在顺时针方向选择一个位置,B在逆时针选择一个位置,且这两个人所选位置的数字相等,然后格子跳到新选的位置上.问最多进行多少轮?有一个限制为每次跳跃不能跨过以前自己曾经选过的格子. 思路:主要是分析问题的本质.其实就是求最长回文子列.f[i][j]为[i,j]的最长回文子列,则答案为max(f[1][i],f[i+1][n]). i

HDU 2069 Coin Change 母函数求解

HDU 2069 Coin Change 母函数求解 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2069 这题比普通的母函数求解题目复杂一点,多了组成个数的限制, 要求组合个数不能超过 100 个硬币,所以将 c1, c2 定义为二维数组, c1[i][j] 表示 c1[结果][组成该结果的个数] ,然后多了一层遍历个数的循环. // 母函数求解 #include <bits/stdc++.h> using namespace std; cons

HDU 4833 Best Financing (DP)

Best Financing Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 29    Accepted Submission(s): 3 Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dat

HDU 1260:Tickets(DP)

Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 923    Accepted Submission(s): 467 Problem Description Jesus, what a great movie! Thousands of people are rushing to the cinema. However,

hdu 1421 搬寝室 (dp)

思路分析: dp[i][j] 表示选取到第 i 个   组成了 j 对的最优答案. 当然排序之后 选取相邻两个是更优的. if(i==j*2) dp[i][j] = dp[i-2][j-1] + w[i]-w[i-2]^2.. else if( i> j*2 ) dp[i][j] = min (dp[i-2][j-1] + ...^2   ,    dp[i-1][j]).... #include <cstdio> #include <iostream> #include &