用dfs实现奇偶数的枚举,如果非正解那么不要WA就行......
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
struct round{
int emax, emin, omax, omin;
}a[300005];
int be[300005], bo[300005];
int ch[300005];int n, m, k;
short route[300005];
bool flag = 0;
void dfs(int pos, int cnt)
{
if(flag)return ;
if(cnt <= 0)return ;
if(cnt <= ch[pos]&&ch[pos] != 0)return ;
if(pos >= m)
{
for(int i = 1;i <= m;i++)
if(route[i] == 0)cout << "Even ";
else cout << "Odd ";
puts("");
flag = 1;
return ;
}
ch[pos-1] = cnt;
//even
route[pos] = 0;
cnt += be[pos];
dfs(pos+1, cnt);
cnt -= be[pos];
//odd
route[pos] = 1;
cnt += bo[pos];
dfs(pos+1, cnt);
cnt -= bo[pos];
route[pos] = -1;
}
int main()
{
int t;
cin >> t;
memset(route, -1, sizeof(route));
while(t--)
{
flag = 0;
memset(ch, 0, sizeof(ch));
int best = 0;
cin >> n >> m >> k;
for(int i = 1;i <= m;i++)
a[i].emax = -inf, a[i].omax = -inf, a[i].emin = inf, a[i].omin = inf;
for(int i = 1;i <= m;i++)
{
bool even = 0, odd = 0;
for(int j = 1;j <= k;j++)
{
int num;
cin >> num;
if(num%2 == 0)a[i].emax = max(a[i].emax, num),a[i].emin = min(a[i].emin, num),even = 1;
else a[i].omax = max(a[i].omax, num),a[i].omin = min(a[i].omin, num),odd = 1;
}
if(odd == 0)be[i] = a[i].emin, bo[i] = -a[i].emax, best -= a[i].emin;
else if(even == 0)bo[i] = a[i].omin, be[i] = -a[i].omax, best -= a[i].omin;
else be[i] = -a[i].emax, bo[i] = -a[i].omax, best += min(a[i].omax, a[i].emax);
}
if(best >= n)
{
cout << -1 << endl;
continue;
}
dfs(1, n);
if(!flag)cout << -1 << endl;
}
return 0;
}