int ways(int sum, int n, int cent) // cent is maxCent allow to use. { if (sum == n) return 1; // this way is good. if (sum > n) return 0; // this way is bad. int ways; // sum < n if (cent >= 25) ways += ways(sum + 25, n , 25); if (cent >= 10) ways += ways(sum + 10, n , 10); if (cent >= 5) ways += ways(sum + 5, n, 5); if (cent >= 1) ways += ways(sum + 1, n, 1); return ways; }
时间: 2024-10-25 18:18:12