zoukankan      html  css  js  c++  java
  • 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 Input
    1 1 3
    0 0 0

    Sample Output
    4

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <string>
     6 # include <cmath>
     7 # include <queue>
     8 # include <list>
     9 # define LL long long
    10 using namespace std ;
    11 
    12 
    13 int c1[10010], c2[10010] ;
    14 int w[4] = {0 , 1 , 2 , 5};
    15 int num[5];
    16 
    17 int main()
    18 {
    19     //freopen("in.txt","r",stdin) ;
    20     int n ;
    21     while(scanf("%d %d %d", &num[1], &num[2], &num[3])!= EOF )
    22     {
    23         if (num[1] == 0 && num[2] == 0 && num[3] == 0)
    24             break ;
    25         int Max = num[1]*w[1]+num[2]*w[2]+num[3]*w[3];
    26 
    27         memset(c1, 0, sizeof(c1));
    28         memset(c2, 0, sizeof(c2));
    29         int i , j , k ;
    30         for(i=0; i<=w[1]*num[1]; i+=w[1])
    31             c1[i] = 1;
    32         int len = w[1]*num[1];
    33         for(i=2; i<=3; ++i)
    34         {
    35             for(j=0; j<=len; ++j)
    36                 for(k=0; k<=w[i]*num[i]; k+=w[i])
    37                 {
    38                     c2[k+j] += c1[j];
    39                 }
    40             len += w[i]*num[i];
    41             for(j=0; j<=len; ++j)
    42             {
    43                 c1[j] = c2[j];
    44                 c2[j] = 0;
    45             }
    46         }
    47         for(i=0; i<=Max; ++i)
    48             if(c1[i] == 0)
    49             {
    50                 printf("%d
    ", i);
    51                 break;
    52             }
    53         if(i == Max+1)
    54             printf("%d
    ", i);
    55     }
    56     return 0;
    57 }
    View Code
  • 相关阅读:
    【bzoj1300】大数计算器
    BZOJ3192: [JLOI2013]删除物品
    BZOJ2818: Gcd
    BZOJ2440: [中山市选2011]完全平方数
    BZOJ3994: [SDOI2015]约数个数和
    BZOJ2154: Crash的数字表格
    BZOJ3529: [Sdoi2014]数表
    BZOJ2301: [HAOI2011]Problem b
    BZOJ1562: [NOI2009]变换序列
    BZOJ1059: [ZJOI2007]矩阵游戏
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4830979.html
Copyright © 2011-2022 走看看