USACO subset TLE code

/*BF
ID:kevin_s1
PROG:subset
LANG:C++
*/

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath>

using namespace std;

//gobal variable====
int N;
int sum;
int result;
//==================


//function==========
void DFS(int i, int count){
	if(i > N)
		return;
	if(count == sum - count){
		result++;
		return;
	}
	DFS(i + 1, count);
	DFS(i + 1, count + i);
	return;
}

//==================

int main(){
	freopen("subset.in","r",stdin);
	freopen("subset.out","w",stdout);
	cin>>N;
	sum = N * (N + 1) / 2;
	if(sum % 2 == 1){
		cout<<"0"<<endl;
	}
	else if(sum % 4 != 0 && (sum + 1) % 4 != 0){
		cout<<"0"<<endl;
	}
	else{
		result = 0;
		DFS(1, 0);
		cout<<result<<endl;
	}
	return 0;
}

你可能感兴趣的:(USACO subset TLE code)