Google笔试题
Google笔试被拒,百度3面居然都挂了,还好,明天微软笔试。。。
有数量不限的面值为100,50,20,10,5,1元的纸币,问要组成N(N<=10^6)共有多少种组合方式?(Google笔试题)
#include <cstdio>
#define COM_LEN 6
using namespace std;
int com[COM_LEN] = {1, 5, 10, 20, 50, 100};
void cal_combinations(int num, int *arr, int index, int &res) {
if (0 == num) {
++res;
return;
}
if (index < 0)
return;
int i, t;
t = num / com[index];
for (i = 0; i <= t; ++i) {
cal_combinations(num - com[index] * i, arr, index - 1, res);
}
}
int main() {
int i, res;
for (i = 1; i <= 200; ++i) {
res = 0;
cal_combinations(i, com, COM_LEN - 1, res);
printf("%d->%d\n", i, res);
}
return 0;
}
浙公网安备 33010602011771号