跳到正文

个人记录

10/06改错

LYZ24约 8 分钟
原文
文章信息与版本

文章信息

发布
2026年10月6日
收录
2026年10月6日
更新
2026年11月22日
篇幅
约 8 分钟

版本

  1. v2当前
  2. v1
第 2 题: rune 符文石 (疑似错题)                                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
第 4 题: julian 儒略历                                                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.题目大意:

日期大模拟题

  • 15821582 年以前和以后使用不同的闰年规则
  • 15821582 年 1010 月 44 日的下一天直接变成 1010 月 1515 日。

2.思路:

不断进位。

3.代码:

C++
#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:讨厌模拟。

第 5 题: chess 西洋棋                                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.题目大意:

在一个带权的网格中,棋子只能向下或向右,求最大路径的值和数量。

2.思路:

DP\large DP。

  • 令 fi,j\large f_{i, j} 表示走到 (i,j)\large (i, j) 的最大权值,易得 fi,j=max(fi−1,j,fi,j−1)\large f_{i,j} = max(f_{i-1,j},f_{i,j-1})。
  • 令 gi,j\large g_{i,j} 表示走到 (i,j)(i,j) 的最大路径数量,因为只能从上方或左方转移,故继承 fi,j\large f_{i, j} 较大者,若相等则累加。

3.代码:

C++
#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:注意边界!(a[i][j]<0a[i][j] < 0)

第 6 题: puzzle 解迷题                                                                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.题目大意:

用不同的斐波那契数组成数字 nn,有多少种不同的方法。

2.思路:

枚举子集+剪枝。

  • 令 dfs(x,s)\large dfs(x,s) 表示处理第 xx 个数,当前的和为 ss。

剪枝:

  • s>ns > n
  • s+res<ns + res < n (resres 指剩余数之和)
  • 倒序搜索(由大致小)

3.代码:

C++
#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;
}
原文