[JZOJ 5778] 没有硝烟的战争

思路:
\(dp[i][j] = 0/1\)来表示第\(i\)个动物报的数字是\(j\),有无必胜策略。
判断有没有转移就可以了。
输出直接对于每一只动物,看\(dp[i][1->k]\)有没有必胜策略就行了。

#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int a[5010];
bool dp[5010][5010];
int suf[5010][5010];
int main () {
	freopen("vode.in","r",stdin);
	freopen("vode.out","w",stdout);
	scanf("%d %d %d",&n,&m,&k);
	for(int i = 1;i <= n; ++i) {
		scanf("%d",&a[i]);
	}
	for(int i = 1;i <= n; ++i) dp[i][m] = 0;
	for(int i = m - 1;i >= 1; --i) {
		for(int j = n;j >= 1; --j) {
			if(suf[j % n + 1][i + 1] - suf[j % n + 1][min(i + k,m) + 1]) dp[j][i] = 1;
			if(a[j] != a[j % n + 1]) dp[j][i] ^= 1;
			suf[j][i] = suf[j][i + 1] + dp[j][i];
		}
	}
	for(int i = 1;i <= n; ++i) {
		printf("%d ",(suf[i][1] - suf[i][k + 1]) ? a[i] : a[i] ^ 1);
	}
	return 0;
}
/*
Input 1
2 9 2
0 1
Input 2
6 499 5
1 0 0 1 1 0
Input 3
10 100 10
0 0 0 1 1 1 1 0 1 1

Output 1
0 1
Output 2
0 1 1 1 1 0
Output 3
1 1 1 1 1 1 1 1 1 1
*/
原文地址:https://www.cnblogs.com/akoasm/p/9562598.html