额    母函数

#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. Android之手机屏幕的获取

    屏幕区域的获取: activity.getWindowManager().getDefaultDisplay(); 应用区域的获取: Rect outRect = new Rect(); activi ...

  2. 关于在windows7中使用Virtual Box 按照 安卓虚拟机几个注意事项

    1.选择安卓原生镜像的问题 选择带PC的字眼的,也就是给平板PC使用的那个,我使用的版本是android-x86-4.0-r1-eeepc.iso其他类似版本也是可以的,因为我已经成功实践啦. 下载地 ...

  3. java集合 collection-list-ArrayList 将自定义对象作为元素存到ArrayList集合中,并去除重复元素。

    import java.util.*; /* 将自定义对象作为元素存到ArrayList集合中,并去除重复元素. 比如:存人对象.同姓名同年龄,视为同一个人.为重复元素. 思路: 1,对人描述,将数据 ...

  4. ZStack中的编程技巧

    1. 像函数一样使用的宏 //这个宏,用来被其他宏使用,构造一个正确有效的表达式.这个适合于一些离散语句的组合,不适合函数的重新命名 #define st(x)      do { x } while ...

  5. javascript 代码优化工具 UglifyJS

    安装: 1. 安装 node.js 环境 (这个不用我教了吧,网上教程一大堆哦.) 2. 进入 https://github.com/mishoo/UglifyJS  右上角 “Download” Z ...

  6. 好用的ssh工具oh-my-zsh / iterm2

    The manual way 1. Clone the repository: git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh- ...

  7. 利用javascript调用摄像头,可以配合socket开发监控系统

    <html> <head> <meta http-equiv="content-type" content="text/html; char ...

  8. MongoDB之【增加用户认证、增加用户、删除用户、修改用户密码、读写权限、只读权限】

    说明:增加用户是针对数据库进行操作 1.进入到数据库 use dbname 2.针对当前数据库添加用户 权限是针对当前数据 1.添加并验证用户 > use admin > db.addUs ...

  9. 简单3D翻转

    1.先上图~~~ 2.代码 html部分 <body> <div id="my3d"> <div id="box"> < ...

  10. 安装 php 转

    一 安装 php 命令: sudo apt-get install libapache2-mod-php5 php5 出现了如下错误: 按照方案一 解决了此问题. 一下 from   http://w ...