10/06改错
| :::info[第 2 题: rune 符文石 (疑似错题) |
|---|
| :::info[第 4 题: julian 儒略历 |
| ### 1.题目大意: |
| 日期大模拟题 |
| - |
| - |
| ### 2.思路: |
| 不断进位。 |
| ### 3.代码: |
| ~~~cpp |
| #include<bits/stdc++.h> |
| using namespace std; |
| typedef long long ll; |
| ll day = 1, month = 1, year = 1; |
| string s[] = {"DEC", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; |
| ll mon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
| bool isr(ll x) { |
| if (x <= 1582) return x % 4 == 0; |
| else if (x % 100 == 0) return x % 400 == 0; |
| else return x % 4 == 0; |
| } |
| int nian(ll x) { |
| if (x == 1582) return 355; |
| else if (isr(x)) return 366; |
| else return 365; |
| } |
| int yue(int ni, int yu) { |
| if (ni == 1582 && yu == 10) return 21; |
| if (yu == 2) { |
| if (isr(ni)) return mon[yu - 1] + 1; |
| else return mon[yu - 1]; |
| } else return mon[yu - 1]; |
| } |
| int main() { |
| ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); |
| cin >> day; |
| day++; |
| while (day > nian(year)) { |
| day -= nian(year); |
| ++year; |
| } |
| while (day > yue(year, month)) { |
| day -= yue(year, month); |
| ++month; |
| } |
| cout << day << " " << s[month] << " " << year; |
| return 0; |
| } |
| ~~~ |
| ps:讨厌模拟。 |
| ::: |
| :::info[第 5 题: chess 西洋棋 |
| ### 1.题目大意: |
| 在一个带权的网格中,棋子只能向下或向右,求最大路径的值和数量。 |
| ### 2.思路: |
| - 令 |
| - 令 |
| ### 3.代码: |
| ~~~cpp |
| #include<bits/stdc++.h> |
| using namespace std; |
| typedef long long ll; |
| const int N = 2026; |
| const ll MOD = 1e9 + 7; |
| int n, m; |
| ll a[N][N]; |
| ll dp[N][N]; |
| ll cnt[N][N]; |
| int main() { |
| ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); |
| cin >> n >> m; |
| for (int i = 1; i <= n; ++i) |
| for (int j = 1; j <= m; ++j) |
| cin >> a[i][j]; |
| dp[1][1] = a[1][1]; |
| cnt[1][1] = 1; |
| for (int i = 1; i <= n; ++i) { |
| for (int j = 1; j <= m; ++j) { |
| if (i == 1 && j == 1) continue; |
| if (i == 1) { |
| dp[i][j] = dp[i][j - 1] + a[i][j]; |
| cnt[i][j] = cnt[i][j - 1] % MOD; |
| } else if (j == 1) { |
| dp[i][j] = dp[i - 1][j] + a[i][j]; |
| cnt[i][j] = cnt[i - 1][j] % MOD; |
| } else { |
| if (dp[i][j - 1] > dp[i - 1][j]) { |
| dp[i][j] = dp[i][j - 1] + a[i][j]; |
| cnt[i][j] = cnt[i][j - 1]; |
| } else if (dp[i - 1][j] > dp[i][j - 1]) { |
| dp[i][j] = dp[i - 1][j] + a[i][j]; |
| cnt[i][j] = cnt[i - 1][j]; |
| } else { |
| dp[i][j] = dp[i - 1][j] + a[i][j]; |
| cnt[i][j] = (cnt[i][j - 1] + cnt[i - 1][j]) % MOD; |
| } |
| cnt[i][j] %= MOD; |
| } |
| } |
| } |
| cout << dp[n][m] << "\n" << cnt[n][m] % MOD; |
| return 0; |
| } |
| ~~~ |
| ps:注意边界!( |
| ::: |
:::info[第 6 题: puzzle 解迷题
1.题目大意:
用不同的斐波那契数组成数字
2.思路:
枚举子集+剪枝。
- 令
\large dfs(x,s) 表示处理第x 个数,当前的和为s 。剪枝:
-
s > n -
- 倒序搜索(由大致小)
3.代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e8 + 50; ll n, len; ll f[100] = {1, 1}, ans; ll d[100]; void dfs(ll x, ll s) { if (x == 0) { if (s == n) ++ans; return; } if (s > n) return; if (s + d[x] < n) return; dfs(x - 1, s); dfs(x - 1, s + f[x]); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 2; ; ++i) { f[i] = f[i - 1] + f[i - 2]; len++; if (f[i] > n) break; } for (int i = 1; i <= len; ++i) { d[i] = d[i - 1] + f[i]; } dfs(len, 0); cout << ans; return 0; }:::