摘要: 动态规划中得到具体决策方案 最长公共子序列 #include <iostream> #include <vector> #include <string> using namespace std; // 最大字符串长度 const int MAXN = 5001; // dp[i][j] 表示 s1 阅读全文
posted @ 2025-05-15 13:16 n1ce2cv 阅读(0) 评论(0) 推荐(0)
摘要: 动态规划中优化枚举 1235. 规划兼职工作 #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int jobScheduling(vect 阅读全文
posted @ 2025-05-14 23:07 n1ce2cv 阅读(2) 评论(0) 推荐(1)
摘要: const关键字 1. 常量变量 当 const 用于普通变量时,它表示该变量的值在初始化后不能被修改。 const int x = 10; x = 20; // 错误,不能修改常量变量 2. 常量成员函数 当 const 用于成员函数时,表示该函数不会修改对象的状态。通常用于 getter 函数。 阅读全文
posted @ 2025-05-14 18:42 n1ce2cv 阅读(3) 评论(0) 推荐(0)
摘要: 左值右值 1. 概念 概念 简明解释 左值(lvalue) 有名字、有地址的对象,能出现在赋值号左边 右值(rvalue) 没有名字、临时存在的值,只能出现在赋值号右边 举例: int a = 10; int b = a + 5; 表达式 类型 说明 a 左值 有名字,可以 &a 取地址 10 右值 阅读全文
posted @ 2025-05-14 18:41 n1ce2cv 阅读(3) 评论(0) 推荐(0)
摘要: 引用的使用场景 1. 函数参数传递(避免拷贝,提高效率) 当函数参数是一个大型对象(如结构体、vector、string),如果传值会产生拷贝,浪费性能: void modify(string &s) { // 用引用传递,避免拷贝 s += " modified"; } 如果用: void mod 阅读全文
posted @ 2025-05-14 01:37 n1ce2cv 阅读(5) 评论(0) 推荐(0)
摘要: 动态规划中优化枚举 121. 买卖股票的最佳时机 #include <iostream> #include <vector> using namespace std; class Solution { public: int maxProfit(vector<int> &prices) { int 阅读全文
posted @ 2025-05-13 22:55 n1ce2cv 阅读(2) 评论(0) 推荐(0)
摘要: C++编译过程 源文件 #include <iostream> #define M "Result: " int add(int a, int b) { return a + b; } int main() { int result = add(3, 4); // 在预处理阶段 M 会被替换成 "R 阅读全文
posted @ 2025-05-13 17:13 n1ce2cv 阅读(1) 评论(0) 推荐(0)
摘要: 数位DP(下) P2657 [SCOI2009] windy 数 #include <iostream> #include <vector> using namespace std; vector<vector<vector<int>>> dp; // 剩下 len 位没有确定 // 上一位数字为 阅读全文
posted @ 2025-05-13 13:54 n1ce2cv 阅读(4) 评论(0) 推荐(1)
摘要: 数位DP(上) 357. 统计各位数字都不同的数字个数 using namespace std; class Solution { public: int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10 阅读全文
posted @ 2025-05-12 23:45 n1ce2cv 阅读(3) 评论(0) 推荐(1)
摘要: 状压DP(下) 1434. 每个人戴不同帽子的方案数 #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int MOD = 1e9 + 7; 阅读全文
posted @ 2025-05-12 15:47 n1ce2cv 阅读(3) 评论(0) 推荐(0)