online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include<bits/stdc++.h> using namespace std; const int MAXN=50; int stickNum, maxLen; int stick[MAXN]; bool use[MAXN]; bool DFS(int pos, int group, int sum, int target){ if (0 > pos) return false; if (1 == group) return true; int prev = -1; for (int i = pos; 0 <= i; --i) { if (prev == stick[i] || use[i] || sum + stick[i] > target) continue; prev = stick[i]; use[i] = true; if (target == sum + stick[i]) { int j = stickNum - 1; while (0 <= j && use[j]) j--; if (DFS(j, group - 1, 0, target)) return true; } else if (DFS(i - 1, group, sum + stick[i], target)) return true; use[i] = false; if (0 == sum) return false; } return false; } int main(){ while(scanf("%d",&stickNum) and stickNum){ int total = 0; for (int i = 0; i < stickNum; i++) { scanf("%d", &stick[i]); total += stick[i]; } sort(stick, stick + stickNum); memset(use, 0, sizeof(use)); for (int i = stick[stickNum - 1]; i <= total; ++i) { if (0 != total % i || total / i > stickNum) continue; if (DFS(stickNum - 1, total / i, 0, i)) { printf("%d\n", i); break; } } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue