第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); } } ... }
点赞 评论

相关推荐

牛客54175811...:今年对双非很难。1、争取一段大厂实习经历,2、狂磕八股,3、再跑个难度提升的项目。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务