【】 6624 HDU
【】 6625 HDU
【】 6626 HDU
【】 6627 HDU
【】 6628 HDU
【】 6629 HDU
[Title] seeking effect each suffix string and a string of the longest prefix length and
[Solutions] extend the KMP bare title (actually card cin, cout qwq)
#include<cstdio> #include<string> #include<iostream> #include<vector> #include<cstring> #include<algorithm> #define ll long long using namespace std; const int MAXN = 1000010; int z[MAXN]; ll query(string s) { ll ans = 0; int n = (int)s.length(); for (int i = 1, l = 0, r = 0; i < n; ++i) { if (i <= r) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } for (int i = 1; i < n; i++) { if (z[i] == 0) ans++; else { if (z[i] + i == n) ans += z[i]; else ans += z[i] + 1; } //printf("%d ", z[i]); } return ans; } string s; int main() { int T; ios_base::sync_with_stdio(0); cin >> T; while (T--) { cin >> s; memset(z, 0, sizeof(z)); cout<< query(s)<<'\n'; } return 0; }
【】 6630 HDU
Title given effect [N], x, y, x is in the order of a, y in the last intermediate arrangement of a digital difference absolute values of adjacent digital not more than 2, the output of how many arrangements
Digital Solutions [] between x and y will be moved to the bottom and then move to the most, and then moved to y, the middle part will move up or move from the cell 3 cell 1 is determined, the answers may be recursive
The following recursive formula: dp [i] = dp [i-1] = dp [i-3]
#include<iostream> #include<vector> #include<cstdio> #include<cstring> #include<iterator> #include<algorithm> const int maxn = 1e5 + 10; long long dp[maxn]; int main() { using namespace std; int T; cin >> T; while (T--) { int N, x, y; cin >> N >> x >> y; if (x > y) swap(x, y); for (int i = x - 5; i <= x + 5; i++) { if (i < 0) continue; dp[i] = 0; } if (x == 1) { dp[x] = 1; for (int i = x + 1; i <= y; i++) { if (i - 3 < 0) dp[i] = dp[i - 1]; else dp[i] = (dp[i - 1] + dp[i - 3]) % 998244353; } } else { dp[x + 1] = 1; for (int i = x + 2; i <= y; i++) { dp[i] = (dp[i - 1] + dp[i - 3]) % 998244353; } } if (y == N) cout << dp[y] << "\n"; else cout << dp[y - 1] << "\n"; } }
【】 6631 HDU
【】 6632 HDU
【】 6633 HDU