Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助呀!!!!!!!!!!为什么TLE了.#include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <stack> using namespace std; const int maxn=40; int A[maxn]; bool visit[maxn]; int cmp(const int a,const int b){ return a>b; } bool dfs(int N,int n,int nowlens,int len){ if(n==0&&nowlens==len) return true; if(nowlens==len) nowlens=0; for(int i=0;i<N;++i){ if(visit[i]==true) continue; if(nowlens+A[i]<=len){ visit[i]=true; if(dfs(N,n-1,nowlens+A[i],len)==true) return true; visit[i]=false; if(nowlens==0||nowlens+A[i]==0) break; } } return false; } int main(){ // freopen("in.txt","r",stdin); int n; scanf("%d",&n); stack<int> st; while(n--){ memset(visit,false, sizeof(visit)); memset(A,0,sizeof(A)); int m,ans; int sum=0; scanf("%d",&m); for(int i=0;i<m;++i){ scanf("%d",&A[i]); sum+=A[i]; } sort(A,A+m,cmp); for(int len=A[0];;++len){ if(sum%len==0){ if(dfs(m,m,0,len)){ ans=sum/len; break; } } } if(ans%4==0){ printf("yes\n"); } else{ printf("no\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator