NYOJ之题目325 zb的生日
--------------------------------------
刷一辈子水题...
AC代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()){ int n=sc.nextInt(); int x[]=new int[n]; while(--n>=0) x[n]=sc.nextInt(); int ans=dfs(x,0,0,0); System.out.println(ans); } } public static int dfs(int x[],int index,long s1,long s2){ if(index==x.length) return (int) Math.abs(s1-s2); return Math.min(dfs(x,index+1,s1+x[index],s2), dfs(x,index+1,s1,s2+x[index])); } }
题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=325