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

相关推荐

xxxxOxo:这公司幽默得很,要了简历半天一点动静都没有,过一会就给你发个邮件让你做测试,做完又没后文了,纯溜人
点赞 评论 收藏
分享
02-28 17:01
门头沟学院 C++
俊朗的铁猫希望被捞:兄弟如果只想搞钱的话,你这个简历最适合的其实是辅导机构做dai写啥的真的特别赚
点赞 评论 收藏
分享
牛客网
牛客企业服务