360笔试散步题91% 求解
#include<iostream> #include<vector> using namespace std; vector<int> res; int M, N; void findWay(int i, int index, vector<int> &road){ if (i < 1 || i > N) return; if(index == road.size()){ if (i >= 1 && i <= N) res.push_back(i); return; } findWay(i - road[index], index + 1, road); findWay(i + road[index], index + 1, road); } int main(){ int tmp; cin >> N >> M; vector<int> road; for (int i = 0; i < M; i++){ cin >> tmp; road.push_back(tmp); } for (int i = 1; i <= N; i++) findWay(i, 0, road); vector<int> rres(res.size()); for (int i = 0; i < res.size(); i++) rres[res[i]]++; int ways = 0; for (int i = 0; i < rres.size();i++) if (rres[i] != 0) ways++; cout << ways; return 0; }
调测试用例去了。。代码有点丑陋,多担待,差那 9%差在哪了。。。求大佬指错
#360公司##笔试题目#