额    母函数

#include <cstdio>
#include <cstring> int a[3],b[3]= {1,2,5};
int c1[10001],c2[10001],sum; int main()
{
while(scanf("%d%d%d",&a[0],&a[1],&a[2]) && a[0]+a[1]+a[2])
{
sum=a[0] + 2*a[1] + 5*a[2];
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
c1[0] = 1;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j <= sum; j++)
if(c1[j])
for(int k = 0; j+k <= sum && k <= b[i]*a[i]; k += b[i])
c2[k+j] += c1[j];
for(int j = 0; j <= sum; j++)
{
c1[j] = c2[j];
c2[j] = 0;
}
}
int i;
for(i = 0; i <= sum; i++)
if(!c1[i])
break;
printf("%d\n",i);
}
return 0;
}

因为输出错 wa好几遍

#include <cstdio>
#include <cstring> int a[3],b[3] = {1, 2, 5};
int c[10001], sum;
int c2[10001]; int main()
{
    while(scanf("%d%d%d",&a[0],&a[1],&a[2]) && a[0]+a[1]+a[2])
    {
        sum = a[0] + 2*a[1] + 5*a[2];
        memset(c, 0, sizeof(c));
        memset(c2, 0, sizeof(c2));
        c[0] = 1;
        int v = 0;
        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j <= v; j++)
                if(c[j])
                    for(int k = 1; k <= a[i]; k++)
                        c2[k*b[i]+j] = 1;
            v += a[i]*b[i];
            for(int j = 0; j <= v; j++)
            {
                if(!c[j])
                    c[j] = c2[j];
                c2[j] = 0;
            }
        }
        int i;
        for(i = 0; i <= sum; i++)
            if(!c[i])
                break;
        printf("%d\n",i);
    }
    return 0;
}

hdu 1085的更多相关文章

  1. HDU 1085 Holding Bin-Laden Captive!(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085 解题报告:有1,2,5三种面值的硬币,这三种硬币的数量分别是num_1,num_2,num_5, ...

  2. hdu 1028 && hdu 1398 && hdu 1085 && hdu 1171 ——生成函数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 就是可以用任意个1.2.3....,所以式子写出来就是这样:(1+x+x^2+...)(1+x^2+ ...

  3. HDU 1085 Holding Bin-Laden Captive! 活捉本拉登(普通型母函数)

    题意: 有面值分别为1.2.5的硬币,分别有num_1.num_2.num_5个,问不能组成的最小面值是多少?(0<=每种硬币个数<=1000,组成的面值>0) 思路: 母函数解决. ...

  4. HDU 1085 Holding Bin-Laden Captive --生成函数第一题

    生成函数题. 题意:有币值1,2,5的硬币若干,问你最小的不能组成的币值为多少. 解法:写出生成函数: 然后求每项的系数即可. 因为三种硬币最多1000枚,1*1000+2*1000+5*1000=8 ...

  5. HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  6. HDU 1085 Holding Bin-Laden Captive! (母函数)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  7. hdu 1085 Holding Bin-Laden Captive!

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...

  8. hdu 1085 Holding Bin-Laden Captive! (母函数)

    //给你面值为1,2,5的三种硬币固定的数目,求不能凑出的最小钱数 //G(x)=(1+x+...+x^num1)(1+x^2+...+x^2num2)(1+x^5+,,,+x^5num3), //展 ...

  9. hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)

    有num1个 1 ,num2个 2 ,num3个 5问它们不能组成的最小正整数是谁 样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)展开后 X4的系数为0 Sample Input1 ...

随机推荐

  1. 北大ACM(POJ1001-Exponentiation)

    Question:http://poj.org/problem?id=1001问题点:大数运算(求幂) #include <iostream> using namespace std; # ...

  2. EFFECTIVE JAVA 第十一章 系列化

    EFFECTIVE  JAVA  第十一章  系列化(将一个对象编码成一个字节流) 74.谨慎地实现Serializable接口 *实现Serializable接口付出的代价就是大大降低了“改变这个类 ...

  3. Bootstrap学习笔记(三) 网格系统

    4-1实现原理 网格系统的实现原理非常简单,仅仅是通过定义容器大小,平分12份(也有平分成24份或32份,但12份是最常见的),再调整内外边距,最后结合媒体查询,就制作出了强大的响应式网格系统.Boo ...

  4. 再说 extern "C"

    早知道 C++ 源文件中要调用C语言函数需要在函数申明时 指定extern "C": 要不然可以编译通过,但连接时提示找不到什么什么符号,原因是C和C++生成的函数名不一样,ext ...

  5. 《QQ欢乐斗地主》山寨版

    使用Cocos2d-x编写,模仿<QQ欢乐斗地主>的界面实现了一个具有简单AI的单机版斗地主游戏. 游戏的详细说明请查看游戏目录下的help.txt文件. 下载地址: http://dow ...

  6. C++ 数组名作为函数参数 都是我的错

    ]) { cout<<sizeof(arr); } 这样一道题,我以为输出的是100呢……32位系统,结果是4 因为:数组名在函数体中被当成一个指针来使用 #include <ios ...

  7. Eclipse必须掌握的快捷键

    Eclipse快捷键 Ctrl +  / 添加//注释.删除//注释 Ctrl + 1 快速修复错误 Ctrl + Shift + f 格式化文档 Shift + Enter Shift + Ctrl ...

  8. JavaScript jQuery 入门回顾

    ​$符号 $是著名的jQuery符号.实际上,jQuery把所有功能全部封装在一个全局变量jQuery中,而$也是一个合法的变量名,它是变量jQuery的别名: window.jQuery; // j ...

  9. [DevExpress]GridControl 列头绘制Checkbox

    关键代码: /// <summary> /// 为列头绘制CheckBox /// </summary> /// <param name="view" ...

  10. C# 与C++的数据转换

    一.类型转化 下面重点罗列下常用的类型转化. C++类型 C#类型 备注说明 Int Int16.Int32 没有悬念,直接转化 Uint UInt16.Uint32.int 在程序中,不太清楚是,就 ...