标签:space tps == set lan line efi def 最长路径
https://codeforces.com/contest/1476/problem/D
给 \(n + 1\) 个点和它们之间连接关系, 两点之间是单向的, 每走过一条边, 所有的边反向, 问从某个点开始出发, 能走过的最长的路径是多少
一开始以为要建图, 实际上算是线性dp
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
const int N = 3e5 + 7;
char s[N];
int l[N], r[N];
int main() {
IO;
int _;
cin >> _;
while (_--) {
memset(l, 0, sizeof l);
memset(r, 0, sizeof r);
int n;
cin >> n;
cin >> s + 1;
for (int i = 1; i <= n; ++i)
if (s[i] == ‘L‘) {
l[i] = 1;
if (i >= 2 && s[i - 1] == ‘R‘) l[i] += l[i - 2] + 1;
}
for (int i = n - 1; i >= 0; --i)
if (s[i + 1] == ‘R‘) {
r[i] = 1;
if (i + 2 <= n && s[i + 2] == ‘L‘) r[i] += r[i + 2] + 1;
}
for (int i = 0; i <= n; ++i) cout << l[i] + r[i] + 1 << " ";
cout << ‘\n‘;
}
return 0;
}
标签:space tps == set lan line efi def 最长路径
原文地址:https://www.cnblogs.com/phr2000/p/14354798.html