Getting the cognitive function of the mother

Build on the progress, just read a blog about speaking generating function, feel good talking now to digest what to write something yourself.
The blog address
to HDU OJ currency exchange issues which entitled example
(look at the recommendations and then resolve this blog's look at this, or will not read ...)

Problem Description
just 1 minute, 2 minutes, 3 minutes in a country coins, money converted into N coins against a variety of methods. Please programmed to calculate how many there are against the law.
Input
per line is a positive integer N, N is less than 32,768.
Output
corresponding to the number of exchange method for each input and output.
The Input the Sample
2934 12553
the Sample the Output
718 831 13,137,761

#include <stdio.h>
#include <stdlib.h>
//HDU OJ 钱币兑换问题
int main()
{
    //需要创建一个数组,该数组的下标就是x的次数,对应的值就是x对应次数的系数
int c[1000000];
//然后是一个需要存储中间操作的数组
int temp[1000000];
int i,j,k;
//然后在这题中,先对一分的这个赋系数的初值,全是一(从x0 到x1000000),而存储中间操作的数组全变成0
for(i=0;i<1000000;i++){
    c[i]=1;
    temp[i]=0;
}
//然后就要开始前一项和后一项相乘了,然后把相乘的值存在第一项中,因为这个问题只涉及三项,所以就是i从2到三
for(i=2;i<=3;i++){
    for(j=0;j<1000000;j++){//这个就是第一项,代表的是x0 x1 x2 x3... j代表的就是对应系数
        for(k=0;k+j<=1000000;k+=i){//这个就是第二项,本题的第二项就是 x0 x2 x4.。。k代表的是对应系数
            //k+j的意思也就是(j1+j2)*(k1+k2)=j1*k1+j1*k2+j2*k1+j2*k2 这样子的 而j和k是次数 ,两项相乘等于次数相加
                temp[k+j]+=c[i];

        }
    }
    //再把中间操作的值放到最终目的地
    for(j=0;j<1000000;j++){
        c[i]=temp[i];
        temp[i]=0;
    }
}
    int n;//输入需要的硬币数
    scanf("%d",&n);
    printf("%d\n",c[n]);


return 0;
}

Such topics also need a lot of effort to look at a few questions to entry!

Published 72 original articles · won praise 5 · Views 2826

Guess you like

Origin blog.csdn.net/qq_41115379/article/details/104848760