Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cmath>
- #include <iostream>
- #include <map>
- #include <set>
- #include <string>
- #include <tuple>
- #include <unordered_map>
- #include <unordered_set>
- #include <vector>
- typedef long long ll;
- using namespace std;
- // Калькулятор
- int main1() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0;
- cin >> n;
- // 0 0 в dp[0] и dp[1] уже
- vector<int> dp(n + 1);
- for (int i = 2; i <= n; ++i) {
- int min_count = dp[i - 1];
- if (i % 2 == 0) min_count = min(min_count, dp[i / 2]);
- if (i % 3 == 0) min_count = min(min_count, dp[i / 3]);
- dp[i] = min_count + 1;
- }
- cout << dp[n] << endl;
- return 0;
- }
- // Пути черепашки
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0, m = 0;
- cin >> n >> m;
- vector<string> p(n);
- for (int i = 0; i < n; ++i) cin >> p[i];
- vector<vector<ll>> dp(n, vector<ll>(m));
- dp[0][0] = 1;
- for (int i = 1; i < m && p[0][i] == '0'; ++i) dp[0][i] = 1;
- for (int i = 1; i < n && p[i][0] == '0'; ++i) dp[i][0] = 1;
- for (int i = 1; i < n; ++i) {
- for (int j = 1; j < m; ++j) {
- if (p[i][j] == '1') continue;
- // Можно без проверок, так как на месте '1' стоят 0.
- if (p[i - 1][j] == '0') dp[i][j] += dp[i - 1][j];
- if (p[i][j - 1] == '0') dp[i][j] += dp[i][j - 1];
- }
- }
- cout << dp[n - 1][m - 1] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement