由于是一面多,采取了笔试和面试各50%的方法来面试(我猜的)
跟面试官问好之后就让我做题了
编码技能考核(请至少完成一道题,40 分钟内完成)
题1
有1,2,5,10等不同零钱各若干,问如果要组合成N元,有多少种不同的组合方式?假设有m种零钱,具体面值存在arr中,要找的钱为n。
例如:arr=[1, 2, 5, 10], n=5, 则有4种组合方式,分别为:
1,1,1,1,1
1,1,1,2
1,2,2
5
提示:不需要给出具体的组合,只需要找出组合的数量
题1(深搜回溯)
#include<iostream>
#include<vector>
using namespace std;
int countQ = 0;
int Target = 0;
int coin[4] = {1,2,5,10};
int total=0;
vector<int> solution;
void dfs(int index)
{
if(total == Target)
{
countQ++;
/*cout<<countQ<<":";
for(int i=0; i<(int)solution.size(); i++)
{
cout<<solution[i]<<" ";
}
cout<<endl;*/
return;
}
if(total >