Untitled
unknown
plain_text
a year ago
1.1 kB
4
Indexable
Never
#include <iostream> using namespace std; int n, k; int maxx = 0; int data[105]; void backtrack(int kk, int doi) { if (doi > 3) { return; } if (kk == k+1) { int dem = 0; for (int i = 1; i <= n; i++) { if (data[i] == 0) { dem ++; } } if (dem > maxx) { maxx = dem; } return; } for (int i = 0; i < 2; i++) { if (i) { for (int j = kk; j <= n; j += (kk+1)) { if (data[j] == 0) { data[j] = 1; } else { data[j] = 0; } } backtrack(kk+1, doi +1); for (int j = kk; j <= n; j += (kk+1)) { if (data[j] == 0) { data[j] = 1; } else { data[j] = 0; } } } else backtrack(kk+1, doi); } } int main() { //freopen("input.txt", "r", stdin); int sl; cin >> sl; for (int stt = 1; stt <= sl; stt++) { cin >> n >> k; maxx = 0; for (int i = 1; i <= n; i++) { data[i] = 0; } for (int i = 1; i <= n; i ++) { cin >> data[i]; } backtrack(1,0); cout <<"#"<<stt<<" "<< maxx<<endl; } return 0; }