hdu 2069

#include "stdio.h"
int main(){
    int num,i1,i2,i3,i4,i5,n;
    int n1,n2,n3,n4,n5;
    while(~scanf("%d",&num)){
        n1=num/50;
        n2=num/25;
        n3=num/10;
        n4=num/5;
        n5=num;
        n=0;
        for(i1=0;i1<=n1;i1++){
            for(i2=0;i2<=n2;i2++){
                for(i3=0;i3<=n3;i3++){
                    for(i4=0;i4<=n4;i4++){
                        for(i5=0;i5<=n5;i5++){
                            if(i1*50+i2*25+i3*10+i4*5+i5==num && (i1+i2+i3+i4+i5)<=100){
                               n++;break;
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n",n);
    }
    return 0;
}

ps:用了五个for,,暴力破解..差点就超出时间,还是用的G++过了...

代码:

时间: 2024-10-24 14:01:50

hdu 2069的相关文章

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 2069二维母函数

显然母函数,有一个地方需要注意.当输入0时,只有一种方法,所以输出1. 代码: 1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 int c1[255][111], c2[255][111]; 7 main() 8 { 9 10 int n, i, j, k, l; 11 int a[

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

Coin Change Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 206964-bit integer IO format: %I64d      Java class name: Main Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We

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

hdu 2069 限制个数的母函数

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

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.

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 1 5 10 25 50 这几种硬币 一共100个(母函数)

题意: 有50 25 10 5 1 的硬币 一共最多有100枚 输入n输出有多少种表示方法 Sample Input1126 Sample Output413 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <string> 6 # include <cmath> 7 # incl