zoukankan      html  css  js  c++  java
  • hdu 2069 母函数 5 types of coins: 50cent, 25cent, 10cent, 5cent, and 1cent. For each input line, output a line containing the number of different wa

    真的很气愤,这题的限制条件有严格控制,代码中体现,我都无语了

    #include <stdio.h>
    #include <stdlib.h>
    int a[260][101],b[260][101];//第二维数组为硬币数 
    int main()
    {
    	int i,j,k,l,n,sum;
    
    	int c[5]={1,5,10,25,50}; 
    
    	for(i=0;i<=260;i++)
    	for(j=0;j<=101;j++) 
    	{
    		a[i][j]=0;b[i][j]=0;
    	}
    
    	for(i=0;i<=100;i++)//用面值为1的硬币组成价值为i(不超过100) 
    	{
                b[i][i]=1;
        }
    
    	for(i=1;i<5;i++)
    	{
    		for(j=0;j<=260;j++)
    		{
    			for(k=0;j+k<=260;k+=c[i])
    			{
    			for(l=0;(l+k/c[i])<=100;l++)
    				a[k+j][l+k/c[i]]+=b[j][l];
    			}
    		} 
    		for(j=0;j<=250;j++)//一定是250 否则过不了 不知道为什么
    			for(l=0;l<=100;++l) 
    			{
    				b[j][l]=a[j][l];
    				a[j][l]=0;
    			}
    	} 
    
    
    	while(scanf("%d",&n)!=EOF)
    	{
    		sum=0;
    		for(i=0;i<=100;i++)
    			sum+=b[n][i]; 
    		printf("%d\n",sum);
    	} 
    
    	return 0;
    }
    

      

  • 相关阅读:
    CF1132G
    CF1129B
    CF1131G
    CF1109D
    CF1110H
    CF1106F
    my.cnf 配置
    mysql 导入导出
    mysql 批量删除表数据
    国内开源镜像站
  • 原文地址:https://www.cnblogs.com/jackes/p/2428698.html
Copyright © 2011-2022 走看看