2016百度笔试题交流
来源:互联网 发布:不要在淘宝搜索血滴子 编辑:程序博客网 时间:2024/05/17 04:42
一道2016年百度研发的笔试题,给出了一个穷举的解法,与大家交流一下,欢迎给出更优解法的思路。
题目如下:
参考代码如下:
#include <iostream>#include <cstdlib>#include <vector>using namespace std;void Cal(const vector<int> &vec, int iBeg, int m, int& k, int& iCurrent, int &iMax){int n=vec.size();if(k==0){if(iCurrent>iMax) {iMax=iCurrent;return ;}return;}for(int i=iBeg;i<n-m*k+1;++i){for(int j=i;j<i+m;++j){iCurrent+=vec[j];}k--;Cal(vec, i+m,m,k,iCurrent,iMax);for(int j=i+m-1;j>=i;--j){iCurrent-=vec[j];}k++; }return;}int main(){int n,m,k;cin>>n>>m>>k;vector<int> vec;for(int i=0;i<n;++i){int tmp=0;cin>>tmp;vec.push_back(tmp);} int iCurrent=0, iMax=0;Cal(vec,0,m,k,iCurrent,iMax);cout<<iMax<<endl;return 0;}
0 0
- 2016百度笔试题交流
- 阿里笔试题—战报交流
- 2016百度春季笔试
- 百度网上笔试题
- 百度网上笔试题
- 百度网上笔试题
- 百度笔试题
- 百度网上笔试题
- 百度笔试题
- 2006百度笔试题
- 百度网上笔试题
- 百度笔试题
- 2007百度笔试题
- 百度笔试题 [软件工程师]
- 百度笔试题
- 2007百度笔试题
- 百度部分笔试题
- 08百度笔试题
- Linux页框管理
- 制作一个简单的表单验证
- U3D自学(一) Enable、Disable及OnEnable()、OnDisable()、OnDestroy()。
- 快速排序
- phonegap学习日志01
- 2016百度笔试题交流
- 网页/微信中的腾讯视频下载方法
- 解决ping时出现?的问题
- 调用内置相机照片,部分手机图片旋转的解决方案
- VirtualBox虚拟机Ubuntu共享win7资源
- gcc & .c | g++ & .cc
- 浅谈搜索引擎工作原理
- 如何在一个div中定位另一个div
- 2015.9.13 PHP学习入门篇