Untitled
unknown
plain_text
2 years ago
1.4 kB
7
Indexable
#include <iostream>
using namespace std;
int arr[101];
int ars[11][101];
int cnt[11];
bool vs[11];
void reset()
{
for(int i = 0; i < 101; i++)
{
arr[i] = 0;
}
for(int i = 0; i < 11; i++)
{
for(int j = 0; j < 101; j++)
{
ars[i][j] = 0;
}
}
for(int i = 0; i < 11; i++)
{
cnt[i] = 0;
vs[i] = false;
}
}
int N, K;
void swp(int &s)
{
if(s == 0)
s = 1;
else
s = 0;
}
int caculate()
{
int cnt = 0;
for(int i = 1; i <= N; i++)
{
if(arr[i] == 0)
{
cnt++;
}
}
return cnt;
}
void bat_tat(int &max, int k)
{
int t = caculate();
if(max < t)
{
max = t;
}
if(k == 3)
{
return;
}
for(int i = 1; i <= K; i++)
{
if(vs[i] == false)
{
vs[i] = true;
for(int j = 0; j < cnt[i]; j++)
{
swp(arr[ars[i][j]]);
}
bat_tat(max, k + 1);
vs[i] = false;
for(int j = 0; j < cnt[i]; j++)
{
swp(arr[ars[i][j]]);
}
}
}
}
int main()
{
int testcase;
cin >> testcase;
for(int tc = 1; tc <= testcase; tc++)
{
cin >> N >> K;
reset();
for(int i = 1; i <= N; i++)
{
cin >> arr[i];
}
for(int i = 1; i <= K; i++)
{
int k = i;
while( k <= N)
{
ars[i][cnt[i]++] = k;
k = k + i + 1;
}
}
int max = 0;
bat_tat(max , 0);
cout<<"#"<<tc<<" "<<max<<endl;
}
}Editor is loading...