zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    sql常用函数
    sql数据库查询
    数据库增删改查
    数据库基本概念
    C#总结
    C#结构体
    C#常用函数类
    初识函数
    C#冒泡排序 折半查找
    12月27日笔记
  • 原文地址:https://www.cnblogs.com/alexyang8/p/2212641.html
Copyright © 2011-2022 走看看