Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不明白怎么会TLE的呢!测试数据全过呢!个人觉得用DFS比较简单啊!。

Posted by lovexinbao at 2011-05-17 19:51:48 on Problem 1014
#include <stdarg.h>
#include <iostream>
#include <vector>
using namespace std;
vector<int> input_number;
vector<int> zhsz;
vector<bool> used;
bool dfs(int left)
{
    for(int i=0;i<int(zhsz.size());i++)
    {   
        if(used[i]==true)
        {
            continue;
        }
        if(left==zhsz[i])
        {           
            return true;
        }
        else if(left<zhsz[i])
        {
            continue;
        }
        else
        {
            used[i]=true;
            if(dfs(left-zhsz[i])==true)
            {
                return true;
            }
            else
            {
                used[i]=false;
                if(i==zhsz.size()-1)
                {
                    return false;
                }
            }
        }       
    }
    return false;
}
int main()
{   
    int jlcs=1;
m1:
    int sum=0,js=0;
    input_number.clear();
    for(int i=0;i<6;i++)
    {
        int n;
        cin>>n;
        input_number.push_back(n);
        if(n==0)
        {
           js+=1;
        }
    }
    if(js==6)
    {
       goto m2;
    }
    for(int i=5;i>=0;i--)
    {
        for(int j=0;j<input_number[i];j++)
        {
            zhsz.push_back(i+1);
            used.push_back(false);
            sum+=i+1;
        }
    }    
    if(dfs(sum/2)==true)
    {
        cout<<"Collection #"<<jlcs<<":"<<endl<<"Can be divided.";
    }
    else{

        cout<<"Collection #"<<jlcs<<":"<<endl<<"Can't be divided.";
    }
    jlcs+=1;
    goto m1;
m2:
    system("pause");

}
用DFS我感觉很好算! 不知道为什么TLE了
谁可以给组变态的数据!。。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator