在一个国家仅有1分,2分,3分硬币,
将钱N分兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
输入样例3
输出样例3
输入样例2934
输出样例718831
#include<iostream> using namespace std; int main() { scanf("%d", &n); int res = 0; //int m = n / 3; for (int j = 0; j <= n; j++) { for (int k = 0; k <= n; k++) { if (2 * j + 3 * k <= n) { res++; //cout << " " << j << " " << k << endl; } } } printf("%d", res); return 0; }
#include<iostream> using namespace std; int main() { scanf("%d", &n); int res = 0; int m = n / 3; for (int j = 0; j <= m; j++) { int k = (n - j * 3) / 2; res += k + 1; } printf("%d", res); return 0; }