[AGC060B] Unique XOR Path
Genius_Star · · 题解
或许更好的阅读体验。
妙妙题。
思路:
首先考虑把问题转化为最多要
考虑把这条路径上全放
如图,黑色是必走路线,那么显然只要在走黑色路径的时候离开了,最后想要走到终点一定会经过若干条红色斜线,于是想到每个红色斜线赋值一个不同的
然后你获得了 WA,这并非最优的安排法,注意到,上面构造只要你碰到了红线就一定会死,那么存不存在这种情况:我至少碰到了三种红线,然后其中两种红线权值一样可以消掉,就还剩下一个。
有的有的,如果有连续的拐点出现:
考虑蓝色路径如果经过两个连续拐点的红色斜线,往后面走一定会再碰到另外一个红线,所以异或不为
拓展开来,如果有连续
于是只要
完整代码:
#include<bits/stdc++.h>
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define popcnt(x) __builtin_popcount(x)
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef long double lb;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
const int N = 105;
inline ll read(){
ll x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-')
f = -1;
c = getchar();
}
while(c >= '0' && c <= '9'){
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return x * f;
}
inline void write(ll x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int T, n, m, k;
char s[N];
inline void solve(){
n = read(), m = read(), k = read();
int sum = 0, ans = 0;
scanf("%s", s + 1);
for(int i = 2; i <= n - 1 + m - 1; ++i){
if(s[i] != s[i - 1])
++sum;
else{
ans += (sum + 1) >> 1;
sum = 0;
}
}
ans += (sum + 1) >> 1;
if(ans <= k)
puts("Yes");
else
puts("No");
}
int main(){
T = read();
while(T--)
solve();
return 0;
}