in c++
Erstellt am: 15. März 2026
Beantwortet mit GPT-5.4 Thinking von Chat01
Erstellt am: 15. März 2026
Beantwortet mit GPT-5.4 Thinking von Chat01
in c++
Use this in the function body:
cppint count(string input1) { const long long MOD = 1000000007; string target = "recursion"; vector<long long> dp(target.size() + 1, 0); dp[0] = 1; // empty subsequence for (char ch : input1) { for (int i = (int)target.size() - 1; i >= 0; --i) { if (ch == target[i]) { dp[i + 1] = (dp[i + 1] + dp[i]) % MOD; } } } return (int)dp[target.size()]; }
How it works:
dp[i] = number of ways to form the first i characters of "recursion".dp[0] = 1.dp[9], since "recursion" has 9 characters.For example:
"rerecursion" → 3"recuursiion" → 4If you want, I can also give the full runnable C++ program with main().
in c++
Use this function body:
cppint highestFloorReached(int input1, int input2, int input3[], int input4[]) { int N = input1; int M = input2; if (N <= 0) return 0; // Adjacency list using raw arrays int *head = new int[N + 1]; for (int i = 0; i <= N; i++) head[i] = -1; int *to = new int[2 * M]; int *next = new int[2 * M]; int idx = 0; for (int i = 0; i < M; i++) { int a = input3[i]; int b = input4[i]; // safety check if (a < 1 || a > N || b < 1 || b > N) continue; to[idx] = b; next[idx] = head[a]; head[a] = idx++; to[idx] = a; next[idx] = head[b]; head[b] = idx++; } // BFS from floor 1 bool *visited = new bool[N + 1]; memset(visited, 0, sizeof(bool) * (N + 1)); int *q = new int[N + 1]; int front = 0, back = 0; q[back++] = 1; visited[1] = true; int ans = 1; while (front < back) { int u = q[front++]; if (u > ans) ans = u; for (int e = head[u]; e != -1; e = next[e]) { int v = to[e]; if (!visited[v]) { visited[v] = true; q[back++] = v; } } } delete[] head; delete[] to; delete[] next; delete[] visited; delete[] q; return ans; }
Idea:
1.If you want, I can also give a version using vector and queue.