Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <deque>
- #include <iostream>
- #include <unordered_map>
- #include <vector>
- int S(int n, std::unordered_map<int, int>& cache) {
- int& value = cache[n];
- if (value != 0) return value;
- return value = S(n - 3, cache) + S(n - 2, cache) + S(n - 1, cache);
- }
- int main1() {
- int n = 0; std::cin >> n;
- std::unordered_map<int, int> cache{{0, 1}, {1, 1}, {2, 2}};
- std::cout << S(n, cache) << std::endl;
- return 0;
- }
- int main2() {
- int n = 0;
- std::cin >> n;
- std::vector<int> v(n + 1);
- v[0] = v[1] = 0;
- for (int i = 2; i <= n; ++i) {
- v[i] = v[i - 1];
- if (i % 2 == 0) v[i] = std::min(v[i], v[i / 2]);
- if (i % 3 == 0) v[i] = std::min(v[i], v[i / 3]);
- ++v[i];
- }
- std::cout << v[n] << std::endl;
- return 0;
- }
- int main3() {
- int n, k; std::cin >> n >> k;
- std::vector<int> x(k);
- int phatka = 0;
- for (int& value : x) {
- std::cin >> value;
- phatka = std::max(value, phatka);
- }
- std::deque<int> dp;
- dp.push_back(0);
- for (int i = 1; i <= n; ++i) {
- dp.push_back(0); // dp[i]
- for (int j = 0; j < k; ++j) {
- if (x[k] <= i) {
- // dp[i ?] = std::min(dp[i ?], dp[i - x[j] ?] + 1);
- }
- }
- if (dp.size() > n - phatka) dp.pop_front();
- }
- return 0;
- }
- struct Node {
- int Parent = 0;
- std::vector<int> Children;
- };
- int main() {
- int n = 0; std::cin >> n;
- std::vector<Node> tree(n);
- for (int i = 0; i < n - 1; ++i) {
- int a, b; std::cin >> a >> b;
- if (a > b) std::swap(a, b);
- tree[b].Parent = a;
- tree[a].Children.push_back(b);
- }
- for (int i = 0; i < n; ++i) {
- std::cout << i << ": ";
- for (int& x : tree[i].Children) std::cout << x << " ";
- std::cout << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement