额    母函数

#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. 关于delegate, category和subclass

    因为自己在学习这三个概念的时候,实在是走了很多的弯路,而且当我意识到这些概念在cocoa中很重要时,我便更糊涂了…或许从C++或者Java转过来的高手一看就明白,所以高手您随便拍砖,指正我的错误:新手 ...

  2. android图片切换ImageSwichter的动画切换效果

    activity_main.xml 控件的线性布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/an ...

  3. winform版简易http服务器

    传人url运行(url以/结尾,例如:http://localhost:8080/web/ 监听这个url// 在浏览器 中输入 http://localhost:8080/web/?name=tes ...

  4. 百度ueditor编辑器背景不显示问题

    网友办法:http://www.hongxuejing.com/hulianwang/ueditor_not_show_background-33.html 官方办法:http://fex-team. ...

  5. Error 1406

    在安装office2010时出现错误提示:Error 1406 解决办法:在注册表中搜索“Image File Execution Options”,设置其权限:添加当前用户并授予所有权限,有时需要授 ...

  6. Cocos开发中Visual Studio下libcurl库开发环境设置

    我们介绍一下win32中Visual Studio下libcurl库开发环境设置.Cocos2d-x引擎其实已经带有为Win32下访问libcurl库,Cocos2d-x 3.x中libcurl库文件 ...

  7. iOS 网络 -- cocoaPods 安装和使用教程

    Code4App 原创文章.转载请注明出处:http://code4app.com/article/cocoapods-install-usage CocoaPods 是什么? 当你开发iOS应用时, ...

  8. Quartz2D 图像处理

    首先感谢一片枫叶总结出这么好的文章,文章出处:http://www.cnblogs.com/smileEvday/archive/2013/05/25/IOSImageEdit.html 本文将为大家 ...

  9. JavaScript--面向对象与原型(15)

    // ECMAScript有两种开发模式:1.函数式(过程化);2.面向对象(OOP); 一 创建对象 1.普通的创建对象 1 // 创建一个对象,然后给这个对象新的属性和方法; 2 var box ...

  10. lex&yacc 9

    the "line 15: error: syntax error" cant stop, if i test the statement "i<=0" ...