|
|
вернуться в форумWhy? Please help me! Why WA on test1. I think this is rigth. #include <iostream> #include <bitset> using namespace std; int main() { int n,max = 1,summa, temp; int *w; cin >> n; w = new int[n]; for(int i = 0; i < n; i++) { max *= 2; cin >> w[i]; } max -= 2; bitset<20> a; temp = w[0]; while(max >= 1) { a = max; summa = 0; for(int i = 0; i < n; i++) { if(a.at(i)) summa += w[i]; else summa -= w[i]; } if(temp > summa && summa >= 0) temp = summa; max--; } cout << temp; return 0; } |
|
|