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 |
哪位大牛能告诉小弟为什么我的总是WA?数据8 1 2 3 4 4 6 6 6也过了,就不知道为什么总是WA#include <iostream> #include <algorithm> using namespace std; int m,sum,t,True,n; int M[22]; bool vis[22]; void dfs(int num,int lenth,int cs);//num为起点,lenth为前num个数的和(可能加/不加) inline bool cmp(int x,int y) { return x>y; } int main() { cin>>n; while(n--) { sum=0; memset(M,0,sizeof(M)); memset(vis,false,sizeof(vis)); cin>>m; for(int i=0;i<m;i++) { cin>>M[i]; sum+=M[i]; } sort(M,M+m,cmp);//降序 int maxn=M[0]; if(sum%4!=0||4*maxn>sum) { cout<<"no"<<endl; continue; } t=sum/4; dfs(0,0,0); if(True) cout<<"yes"<<endl; else cout<<"no"<<endl; } system("pause"); return 0; } void dfs(int num,int lenth,int cs) { if(cs==3) { True=1;return ;} if(lenth==t) dfs(0,0,cs+1); if(True) return ; for(int i=num;i<m;i++) { if(!vis[i]&&M[i]+lenth<=t) { vis[i]=true; dfs(i+1,lenth+M[i],cs); if(True) return ; vis[i]=false; } } } 知道原因了···· 大家注意数据组之间要清理 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator