zoukankan      html  css  js  c++  java
  • hdu 1398 整数划分变形 (母函数)

    有1,4,9,16,25.....2^17这么多面值的硬币,问任意给定一个不大于300的正整数面额,用这些硬币来组成此面额总共有多少种组合种数

    比如10
    全1
    4 + 6个 1
    4+4+1+1
    9+1

    求(1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9+x^10)(1+x^4+x^8)(1+x^9)中
    x^10的系数即可

    只是把模板的 i<=n改成了i*i<=n,
    在k遍历指数时把k=k+i变成了k=k+i*i


    Sample Input
    2
    10
    30
    0

    Sample Output
    1
    4
    27

     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 int c1[10010], c2[10010] ;
    13 int main()
    14 {
    15     //freopen("in.txt","r",stdin) ;
    16     int n;
    17     int i, j, k;
    18     while(cin >> n)
    19     {
    20         if (n == 0)
    21             break ;
    22         for(i=0; i<=n; ++i)
    23         {
    24             c1[i] = 1;
    25             c2[i] = 0;
    26         }
    27         for(i=2; i*i<=n; ++i)
    28         {
    29 
    30             for(j=0; j<=n; ++j)
    31                 for(k=0; k+j<=n; k += i*i)
    32                 {
    33                     c2[j+k] += c1[j];
    34                 }
    35                 for(j=0; j<=n; ++j)
    36                 {
    37                     c1[j] = c2[j];
    38                     c2[j] = 0;
    39                 }
    40         }
    41         cout << c1[n] << endl;
    42     }
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    程序猿节日快乐!
    Haxe UI框架StablexUI的使用备忘与心得(一)
    sudo fdisk -l
    Win7下硬盘安装fedora17
    盎司
    arm-linux工具
    GSM900TCP/UDP连接
    STC51几种简单的延时函数
    STC51六中中断配置点亮一个LED
    LCD1602小程序
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4830662.html
Copyright © 2011-2022 走看看