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 |
请高手帮我看看哪里错了啊?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator