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

请高手帮我看看哪里错了啊?

Posted by boyisjl at 2009-08-30 21:31:21 on Problem 1745
#include <iostream>
using namespace std;

bool T(int n, int div, int a[])
{
    if(n == 1)
    {
        if(a[0] % div == 0)
        {
            cout << "Divisible";
            return true;
        }
        else
            return false;
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            int t1, t2;
            t1 = a[i];
            t2 = a[j];
            a[j] = a[n-1];

            a[i] = t1 + t2;
            if(T(n-1, div, a))
                return true;

            a[i] = t1 - t2;
            if(T(n-1, div, a))
                return true;

            a[i] = t1;
            a[j] = t2;
        }
    }
}


int main()
{
    int n;
    cin >> n;
    int div;
    cin >> div;
    int a[10001];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    T(n, div, a);
    if(!T(n, div, a))
        cout << "Not divisible";
    return 0;
}

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