hdu4277 USACO ORZ

1006 단어 cStringClassimport
import java.util.HashSet;
import java.util.Scanner;

public class Triangle {
	int a,b,c;
	int arr[]=new int[1010],n,sum;
	long M=200010;
	HashSet<Long> mp=new HashSet<Long>();
	void dfs(int d){
		if(d>n){
			if(a+b>c&&a+c>b&&b+c>a){
				int x=Math.min(a,Math.min(b,c));
				int y=Math.max(a,Math.max(b,c));
				mp.add(x+(a+b+c-x-y)*M+y*M*M);
			}
			return;
		}
		sum-=arr[d];
		a+=arr[d];
		dfs(d+1);
		a-=arr[d];
		b+=arr[d];
		dfs(d+1);
		b-=arr[d];
		c+=arr[d];
		dfs(d+1);
		c-=arr[d];
	}
	Scanner scan=new Scanner(System.in);
	void run(){
		int cas=scan.nextInt();
		while(cas-->0){
		n=scan.nextInt();
		sum=0;
		for(int i=1;i<=n;i++){
			arr[i]=scan.nextInt();
			sum+=arr[i];
		}
		a=b=c=0;
		mp.clear();
		dfs(1);
		System.out.println(mp.size());
		}
	}
	public static void main(String[] args){
		new Triangle().run();
	}
}

hashset 되 게 좋아 보인다!
전재 하 다 http://blog.csdn.net/kksleric/article/details/7958600

좋은 웹페이지 즐겨찾기