Count press
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int dp(string& s, vector<string>& v, unordered_map<string, int>& memo) {
if (memo.count(s)) return memo[s];
int maxRemoval = 0;
for (auto& x : v) {
size_t pos = s.find(x);
if (pos != string::npos) {
string new_string = s.substr(0, pos) + s.substr(pos + x.size());
maxRemoval = max(maxRemoval, 1 + dp(new_string, v, memo));
}
}
return memo[s] = maxRemoval;
}
int main() {
int n;
cin >> n;
vector<string> substrings(n);
for (int i = 0; i < n; ++i) {
cin >> substrings[i];
}
string mainString;
cin >> mainString;
unordered_map<string, int> memo;
cout << dp(mainString, substrings, memo);
return 0;
}
FOLDER AREA
#include <iostream>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
pair<double, double> reflectPoint(double px, double py, double x1, double y1, double x2, double y2) {
double A = y2 - y1;
double B = x1 - x2;
double C = x2 * y1 - x1 * y2;
double distance = (A * px + B * py + C) / sqrt(A * A + B * B);
double reflectedX = px - 2 * distance * (A / sqrt(A * A + B * B));
double reflectedY = py - 2 * distance * (B / sqrt(A * A + B * B));
return {reflectedX, reflectedY};
}
int main() {
double area;
cout << "Enter area of the square: ";
cin >> area;
double x1, y1, x2, y2;
cout << "Enter the coordinates of the line (x1 y1 x2 y2): ";
cin >> x1 >> y1 >> x2 >> y2;
double side = sqrt(area);
vector<pair<double, double>> corners = {
{0, 0},
{0, side},
{side, side},
{side, 0}
};
set<pair<double, double>> uniquePoints(corners.begin(), corners.end());
for (const auto& corner : corners) {
auto [rx, ry] = reflectPoint(corner.first, corner.second, x1, y1, x2, y2);
uniquePoints.insert({rx, ry});
}
for (const auto& point : uniquePoints) {
cout << fixed << setprecision(2) << point.first << " " << point.second << endl;
}
return 0;
}
Segment display
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<string>> A = {
{"11111", "11111", "11111", "11111", "11111", "11111", "11111", "10001", "11111", "11111", "10001", "10000", "11111", "10001", "01110", "11111", "11111", "11111", "11111", "11111", "10001", "10001", "10001", "10001", "10001", "11111"},
{"10001", "10001", "10000", "10001", "10000", "10000", "10000", "10001", "00100", "00001", "10010", "10000", "10101", "11001", "10001", "10001", "10001", "10001", "10000", "00100", "10001", "10001", "10001", "00000", "10001", "00000"},
{"10001", "10001", "10000", "10001", "10000", "10000", "10000", "10001", "00100", "00001", "10100", "10000", "10101", "10101", "10001", "10001", "10001", "10001", "10000", "00100", "10001", "10001", "10001", "01010", "10001", "00010"},
{"10001", "10001", "10000", "10001", "10000", "10000", "10000", "10001", "00100", "00001", "11000", "10000", "10101", "10011", "10001", "10001", "10001", "10001", "10000", "00100", "10001", "10001", "10001", "00000", "10001", "00000"},
{"11111", "11111", "10000", "10001", "11111", "11111", "10111", "11111", "00100", "10001", "11111", "10000", "10101", "10001", "10001", "11111", "10101", "11111", "11111", "00100", "10001", "10001", "10101", "00100", "11111", "00100"},
{"10001", "10001", "10000", "10001", "10000", "10000", "10001", "10001", "00100", "10001", "10001", "10000", "10001", "10001", "10001", "10000", "10001", "11000", "00001", "00100", "10001", "10001", "10101", "00000", "00001", "00000"},
{"10001", "10001", "10000", "10001", "10000", "10000", "10001", "10001", "00100", "10001", "10001", "10000", "10001", "10001", "10001", "10000", "10011", "10100", "00001", "00100", "10001", "10001", "10101", "01010", "00001", "01000"},
{"10001", "10001", "10000", "10001", "10000", "10000",