{ "question_id": 1059365, "question_title": "不喜欢带钱的小C", "question_content": "题目描述:\n小C不喜欢带钱,有一次竟被他碰上了一家不能使用移动支付(也不能找钱)的神秘商店。请问小C至少准备多少张RMB才能恰好支付n元。RMB的面额有100元,50元,20元,10元,5元,1元。\n输入格式:\n输入一个整数n\n输出格式:\n最少带几张。\n样例输入1:\n50\n样例输出1:\n1\n约定:\n1<=n<=100", "difficulty": "中等", "answer_id": 1256674, "answer_content": "\n```\n#include \n\nusing namespace std;\n\nint solve(int tar, int * meta, int metan, int * seed = NULL, int seedn = 0)\n{\n\tif (tar == 0)\n\t{\n\t\t//for (int i = 0; i < seedn; i++) cout << seed[i] << \" \";\n\t\t//cout << endl;\n\t\treturn seedn;\n\t}\n\tint min = -1;\n\tint m;\n\tint * seed1 = new int[seedn + 1];\n\tif (seed)\n\t\tmemcpy(seed1, seed, sizeof(int) * seedn);\n\tfor (int i = 0; i < metan; i++)\n\t{\n\t\tif (meta[i] <= tar)\n\t\t{\n\t\t\tseed1[seedn] = meta[i];\n\t\t\tm = solve(tar - meta[i], meta, metan, seed1, seedn + 1);\n\t\t\tif (m != -1 && (min == -1 || min > m))\n\t\t\t\tmin = m;\n\t\t\tbreak;\n\t\t}\n\t}\n\tdelete[] seed1;\n\treturn min;\n}\n\nint main()\n{\n\tint arr[] = { 100, 50, 20, 10, 5, 1 };\n\tint n = 6;\n\tint total;\n\tcin >> total;\n\tint result = solve(total, arr, n);\n\tcout << result << endl;\n\treturn 0;\n}\n\n```\n# 问题解决的话,请点下`采纳`", "tag_name": "c++", "cpp": "#include \nusing namespace std;\nint solve(int tar, int * meta, int metan, int * seed = NULL, int seedn = 0)\n{\n\tif (tar == 0)\n\t{\n\t\treturn seedn;\n\t}\n\tint min = -1;\n\tint m;\n\tint * seed1 = new int[seedn + 1];\n\tif (seed)\n\t\tmemcpy(seed1, seed, sizeof(int) * seedn);\n\tfor (int i = 0; i < metan; i++)\n\t{\n\t\tif (meta[i] <= tar)\n\t\t{\n\t\t\tseed1[seedn] = meta[i];\n\t\t\tm = solve(tar - meta[i], meta, metan, seed1, seedn + 1);\n\t\t\tif (m != -1 && (min == -1 || min > m))\n\t\t\t\tmin = m;\n\t\t\tbreak;\n\t\t}\n\t}\n\tdelete[] seed1;\n\treturn min;\n}\nint main()\n{\n\tint arr[] = { 100, 50, 20, 10, 5, 1 };\n\tint n = 6;\n\tint total;\n\tcin >> total;\n\tint result = solve(total, arr, n);\n\tcout << result << endl;\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600469951", "status": 1, "keywords": "算法高阶,数论算法,算法问题选编,整数的因子分解", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/75.ipynb?type=file" }, "notebook_enable": 1, "author": "ohpatch" }