今晚的牛客模拟笔试第三题咋做的呀

如题...#笔试#
全部评论
https://blog.csdn.net/meihuai7538/article/details/76177549
1 回复 分享
发布于 2020-05-22 10:45
回溯额 void backtrack(int n, int index, vector<bool>& visited, int & count) { if (index == n) { if (visited[n]) { count++; if (count == 1000000007) count = 0; return; } else { count++; if (count == 1000000007) count = 0; count++; if (count == 1000000007) count = 0; return; } } if (visited[index]) { backtrack(n, index + 1, visited, count); } else { for (int i = 0; i < 2; ++i) { if (0 == i) { int temp1 = index ; while (temp1 <= n) { visited[temp1] = true; temp1 += index; } backtrack(n, index + 1, visited, count); int temp2 = index ; while (temp2 <= n) { visited[temp2] = false; temp2 += index; } } else { visited[index] = true; backtrack(n, index + 1, visited, count); visited[index] = false; } } } return;  } int main() { int n = 0; while(cin >> n) { vector<bool> visited(n+1, false); int count = 0; backtrack(n, 2, visited, count); cout << count << endl; } }
点赞 回复 分享
发布于 2020-05-21 21:49
同求。。
点赞 回复 分享
发布于 2020-05-21 22:32

相关推荐

想要offer的牛油果很大方:老哥,你啥时候面的,有timeline吗
点赞 评论 收藏
分享
什么时候才能有offer啊_:十年前我还在刺激战场研究跳伞的底层原理呢
投递牛客等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务