let me count the ways.txt

来自「以前ACM在哈工程HRBEU做的一些简单题目」· 文本 代码 · 共 20 行

TXT
20
字号
#include <stdio.h> 
#define N 5 
#define M 100 
main(){ 
   int coin[N]={1,5,10,25,50}; 
   long table[M]={0}; 
   long cent=0,i=0,j=0; 
   table[0]=1;    
    for(i=0;i<N;i++){ 
      for(j=coin[i];j<M;j++) 
         table[j]+=table[j-coin[i]];                
   }       
   while(scanf("%ld",&cent)==1){                        
       if(table[cent] == 1) 
         printf("There is only 1 way to produce %ld cents change.\n",cent); 
       else 
         printf("There are %ld ways to produce %ld cents change.\n",table[cent],cent);      
   }                             
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?