第3题,10取5,回溯法: public class TenInt { static final int NUM=10; int[] arr; int res; TenInt(){ arr=new int[NUM]; res=Integer.MAX_VALUE; } void dfs(int start, int count, final int total, final int sum){ if(count==5){ res=Math.min(res, Math.abs(total-2*sum)); return; } if(start>=NUM|| count>5){ return; } for(int i=start; i<NUM; i++){ swap(start, i); dfs(start+1, count+1, total,sum+arr[start]); swap(start, i); } } ... }
点赞 评论

相关推荐

头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务