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 |
帮帮忙为什么总是Time Limit Exceeded呢?哪位大虾能帮忙看看呀 #include<iostream> using namespace std; int marble[6]; bool half(int d,int n) { if(d==0) return true; if(n==0) return false; int i; for(i=marble[n-1];i>=0;i--) { if((d-i*n)>=0) { marble[n-1]=marble[n-1]-i; if(half(d-i*n,n-1)) return true; marble[n-1]=marble[n-1]+i; } } return false; } int main() { int sum=0; for(int i=0;i<6;i++) { cin>>marble[i]; sum=sum+marble[i]*(i+1); } for(int i=1;sum>0;i++) { cout<<"Collection #"<<i<<":"<<endl; if(half(sum/2,6)&&sum%2==0) cout<<"Can be divided."<<endl; else cout<<"Can't be divided."<<endl; sum=0; for(int i=0;i<6;i++) { cin>>marble[i]; sum=sum+marble[i]*(i+1); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator