-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.json
1 lines (1 loc) · 26.4 KB
/
content.json
1
{"pages":[{"title":"my first page","text":"Line one, and let’s see what’ll happen with page.What changed?","link":"/my-first-page/index.html"}],"posts":[{"title":"Hello World","text":"Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment","link":"/2022/02/05/hello-world/"},{"title":"My First Post","text":"This is a paragraph of text. yes~$\\alpha$ I think it works this time :D","link":"/2022/02/05/My-First-Post/"},{"title":"make a post by hexo new","text":"Does it work?? (y or n) Let me just upload my english note on February 3rd for a try: MAINslash 斜线。 /, forward slash,正斜线 \\, backward slash,反斜线 hyphen, [ˈhaɪfn] 连字符,即’-‘ recipe, [ˈresəpi] 配方 (日常)食谱 (专业)指编译路径方案 realm,领域 e.g. Reading literature, in particular, as a pastime is the path which leads you to the magic realm of other worlds shaped by a magnificent combination of words, phrases and sentences composing anew and in a totally different way what you experience in your everyday life. literature, [ˈlɪtrətʃə] (专业)文献 failure, [ˈfeɪljə]status, [ˈsteɪtəs] (常见)地位,社会地位;身份 特定的状态 executive, [ɪgˈzekjətɪv] n. 管事的,主要的高级的管事的那些人 e.g. a company executive adj. (作为功能性修饰的)决策、管理相关的 e.g. an executive director excuse, [ɪkˈskjuːs] n. (为找借口而作的)理由,也即借口 v. 接受给出的理由;原谅,宽恕 v. (正当地)说明,解释,辩解 chronic of long duration,长期的 e.g. In fact, the people most likely to become chronic excuse makers are those labeled with success. live up to,达到(要求或期望)reciprocal, [rɪˈsɪprəkl] adj. 互惠的 e.g. she was hoping for some reciprocal comment or gesture. adj. 相互的(mutual)e.g. reciprocal cross 正反交(生物意义的) n. (专业)倒数 e.g. the reciprocal of 2/3 is 3/2 momentum, [məˈmentəm] (日常)动力,势头 (专业)冲量 legacy 遗产 易混词:privacy,隐私 fatigue,疲态heave,拉,引obsessed,[əbˈsest] 迷恋于,沉迷于 易混词:obese, ]əʊˈbiːs],肥胖的 BRANCHflirt (生活)调情;撩;挑逗 (正经一些的)不认真考虑、游戏人生般地对待(with) e.g. Driving carelessly is flirting with disaster: it’s almost like you’re toying with the idea of getting into an accident. on hold (基本)等待(被)呼叫(中) (引申)处于暂缓的搁置的状态 e.g. The project is on hold until we get more money. slack adj. 松弛的,懈怠的(loose) n. 松弛 e.g. cut sth/sb some slack 对…网开一面,给…方便 Well, last but not least, let’s try some markdown functionShow a image by local path: Show a image by url: Create a hyperlink attached to the image: Make a table Syntax Description Test Text Header Title Here’s this Paragraph Text And more Add two code block1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 110;int n, m;char str[N];int num[N];char op[N];int ntt, ott;int pr[N];void eval(){ int b = num[ntt -- ]; int a = num[ntt -- ]; char c = op[ott -- ]; int x; if (c == '+') x = a + b; else if (c == '-') x = a - b; else if (c == '*') x = a * b; else x = a / b; num[ ++ ntt] = x;}int main(){ pr['+'] = pr['-'] = 1; pr['*'] = pr['/'] = 2; scanf("%s", str); int n = strlen(str); n -- ; int i; for (i = 0; i < n; i ++ ) { char c = str[i]; if (isdigit(c)) { int x = 0, j = i; while (j < n && isdigit(str[j])) x = 10 * x + str[j ++ ] - '0'; i = j - 1; num[ ++ ntt] = x; } else if (c == '(') op[ ++ ott] = c; else if (c == ')') { while (op[ott] != '(') eval(); ott -- ; } else { while (ott && op[ott] != '(' && pr[op[ott]] >= pr[c]) eval(); op[ ++ ott] = c; } } while (ott) eval(); printf("%d\\n", num[ntt]); return 0;}/*1+4*5-5/2+(1-1)#19*/ And here comes a hexo command: hexo g -dWith it, you can generate a page and deploy it to your own webpage form local to remote. OK, the above is all the test this time, I hope everything goes well~","link":"/2022/02/05/make-a-post-by-hexo-new/"},{"title":"post a post by myself","text":"It is a almost empty blog.I build it by create it directly and locally.Wish me success!","link":"/2022/02/05/post-a-post-by-myself/"},{"title":"","text":"This a titleAnd this a paragraph. This is the end of this text.This the end of this blog. By the way, the filename of this is different from the previous ones. This time, there is space in it. Let’ see what will happen.","link":"/2022/02/06/pure%20mdfile/"},{"title":"总结","text":"已了解的部分hexo命令相关创建博文 123$ hexo new "my_post_name"$ hexo new page "my_page_name"$ hexo new draft "my_draft_name" 生成网站并且部署到远端 1$ hexo g -d hexo结构相关public为创建后的网站的文件结构。其中img可以存放调用的图片。 scaffolds存放博文模板。默认模板有三:post,page,draft博文生成后分别会存放在\\source\\_posts、\\source和\\source\\_drafts中。自定义的模板都与post模板相同存放在\\source\\_posts中。模板可类似定义为 1234---title: {{ title }}date: {{ date }}--- 即指定典型样式的front_matter部分的属性与值,title和data即为命令调用时传递或产生的变量。front_matter还有的一些属性如下: 12345678---title: 总结date: 2022-02-06 10:17:53tags: [hexo-learning, icarus, blog]category: usagecover: /img/covers/vector_landscape_2.svgthumbnails: /img/covers/vector_landscape_2.svg--- 应用模板后的博文便会以title值作为一级标题,md文件中front_matter后的部分便承接此一级标题往后延展。 source存放博文的相关文件themes则为更改的各hexo主题的目录各.yml文件即为各域下的配置文件图片相关网站中所使用的图片需要相对路径或url。相对路径是指相对于博客public目录(deploy到远端后即为网站的地址)的路径;url则为互联网上所有可以访问的资源(在此便指图片,指jpg、png、svg等) git命令相关git clone, git add, git commit git push and git pullvscode的内置源代码管理以及git lens插件的版本控制功能 以待来日的问题博客的侧边栏布局配置问题关于双栏和三栏的在不同场景下的配置如何实现的问题。目前希望在博文中可以两栏,其他地方三栏=。我们知道,_config.yml为hexo的全局配置,_config.icarus.yml为主题icarus的配置,由文档知,应该还有_config.post.yml对所有文章生效的配置,_config.page.yml对所有自定义页面生效的配置,但是却没有找到这两个配置文件。或许是要我们自己添加,那添加在哪(和_config.yml一样的在本地blog根目录?还是应该在public的哪?),若是添加,那配置文件该写入哪些内容(只用写入目前所需widgets的相关还是还需要写其他的?)。按下不表,以待来日。 git、github访问速度问题由各渠道以及一直以来的了解的信息,使用SwitchHosts修改了本地host(查询了实时的目标IP地址),但后续还是没有解决,用cmd的ping依然可能连接超时,hexo g -d依然可能unable to access 'https://github.com/DIaacKr/diaackr.github.io.git/'以及err: Error: Spawn failed。(但修改后的host方案依然保留着)我看没有哪说改了host也不行的,就看到不知道怎么改host和改host成什么的相关贴文,那或许我哪没搞好?但我估计不会这样。这确实也是挺长期的问题了,没办法这次也没解决。按下不表,以待来日。 博客字体的更换问题感觉这个字体显示得很别扭,比如t都左边不出头什么的,可能需要改下。相关文件应该是在css下的font里但这里的文件们也不那么显然,看到_config.icarus.yml下有相关的font设置,肯定也需要改,然后又涉及到在网上找字体文件资源、怎么下载字体文件、放在哪里是否是自己放、又需不需要自己放、放完又要改哪里和哪里、然后修改、测试、修改、测试等一系列事。按下不表,以待来日。 markdown的公式显示不了的问题用$和$包的也推到远端就显示不好,本地却挺好。如$\\alpha + \\beta = \\beta + \\alpha$猜测是远端没有latex的相关环境?或者md版本有什么问题?或者渲染的哪个环节有问题?按下不表,以待来日。 文章中代码的上栏怎么添加文字的问题按下不表,以待来日。 文章折叠的问题现在是用<!--more-->分隔,此行一下的部分便被折叠,主页上不显示。但显然这样的无法穿插进代码里,所以应该不是最终的解决方法。按下不表,以待来日。 hexo的page布局是什么?文档说是分页,但分页又是什么,创建了个page然后deploy上去又没看到又哪有变化,没有办法。按下不表,以待来日。 archive下的此篇文章的缩略图未显示因为第一次的时候把路径写错了(slash的问题),所以就找不到图片。但之后我把博文删了再重写,首页上的cover显示正常但看下缩略图还是不行,估计得修改缩略图相关文件的东西。按下不表,以待来日。","link":"/2022/02/06/%E6%80%BB%E7%BB%93/"},{"title":"懵懂阶段梳理总结","text":"[TOC] 动态规划数字三角形模型1f[i][j] = max(f[i - 1][j], f[i][j - 1]) + w[i][j] e.g.摘花生1015. 摘花生 - AcWing题库 12345678910f[0][1] = f[1][0] = 0;f[0][2:end] = f[2:end][0] = -INF;for i = 1:n, j = 1:m4f[i][j] = max(f[i - 1][j], f[i][j - 1]) + w[i][j];f[n][m];// f[0][1:m] = f[1:n][0] = 0;// f[i][j] = f[i - 1][j] + f[i][j - 1] + 1; e.g.最低通行费1018. 最低通行费 - AcWing题库 1234567f[0][1] = f[1][0] = 0;f[0][2:end] = f[2:end][0] = INF;for i = 1:n, j = 1:m f[i][j] = min(f[i - 1][j], f[i][j - 1]) + w[i][j];f[n][m]; e.g.方格取数1027. 方格取数 - AcWing题库 1234567891011121314int dx[4] = {-1, -1, 0, 0}, dy[4] = {-1, 0, -1, 0};memset(f, 0, sizeof(f));for (int k = 2; k <= 2 * n; k ++ ) for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= n; j ++ ){ if (k - i < 1 || k - i > n || k - j < 1 || k - j > n) continue; int t = w[i][k - i]; if (i != j) t += w[j][k - j]; for (int u = 0; u < 4; u ++ ) f[k][i][j] = max(f[k][i][j], f[k - 1][i + dx[u]][j + dy[u]] + t); }cout << f[2 * n][n][n] << endl; 最长上升子序列模型e.g.怪盗基德的滑翔翼1017. 怪盗基德的滑翔翼 - AcWing题库 单调子序列的最大长度 12345678910111213141516int res = -INF;for (int i = 1; i <= n; i ++ ){ f[i] = 1; for (int j = 1; j < i; j ++ ) if (a[i] > a[j]) f[i] = max(f[i], f[j] + 1); res = max(res, f[i]);}for (int i = n; i >= 1; i -- ){ f[i] = 1; for (int j = n; j > i; j -- ) if (a[i] > a[j]) f[i] = max(f[i], f[j] + 1); res = max(res, f[i]);}cout << res << endl; e.g.登山1014. 登山 - AcWing题库 12345678910111213141516for (int i = 1; i <= n; i ++ ){ f[i] = 1; for (int j = 1; j < i; j ++ ) if (a[i] > a[j]) f[i] = max(f[i], f[j] + 1);}for (int i = n; i >= 1; i -- ){ g[i] = 1; for (int j = n; j > i; j -- ) if (a[i] > a[j]) g[i] = max(g[i], g[j] + 1);}int res = 0;for (int i = 1; i <= n; i ++ ) res = max(res, f[i] + g[i] - 1);cout << res << endl; e.g.友好城市1012. 友好城市 - AcWing题库 应用题 e.g.最大上升子序列和1016. 最大上升子序列和 - AcWing题库 上升子序列的最大价值 123456789int res = -INFfor (int i = 0; i < n; i ++ ){ f[i] = w[i]; for (int j = 0; j < i; j ++ ) if (w[i] > w[j]) f[i] = max(f[i], f[j] + w[i]); res = max(res, f[i]);}cout << res << endl; e.g.拦截导弹1010. 拦截导弹 - AcWing题库 Dilworth定理:将一个序列划分成若干个单调不升子序列的最小个数等于该序列最长上升子序列的个数 另有贪心作法,XXXX e.g.导弹防御系统187. 导弹防御系统 - AcWing题库 XXXX e.g.最长公共上升子序列272. 最长公共上升子序列 - AcWing题库 遍历时一并记录之前的满足大小条件的最大长度 1234567891011int res = 0;for (int i = 1; i <= n; i ++ ){ int tmp = 1; for (int j = 1; j <= n; j ++ ){ f[i][j] = f[i - 1][j]; if (a[i] > b[j]) tmp = max(tmp, f[i - 1][j] + 1); if (a[i] == b[j]) f[i][j] = max(f[i][j], tmp); if (i == n) res = max(res, f[i][j]); }}cout << res << endl; 背包模型有背包体积$m$,$n$个待决策的物品,每个物品对应有体积$v_i$、价值$w_i$, 对每个物品的决策可能是:选择加入背包、选择不加入背包, 求,对于所有决策可能,背包(中各个物品的集体)的最大价值。 12345678910111213int n, m;int v[N], w[N]; // 1 ~ nint f[N][M]; // (1 ~ n, 0 ~ m)for (int i = 0; i <= m; i ++ ) f[0][i] = 0;for (int i = 1; i <= n; i ++ ) for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]); }cout << f[n][m] << endl; 费用情况以求方案数为例: 限定费用上限; 1234567for (int i = 0; i <= m; i ++ ) f[0][i] = 1;for (int i = 1; i <= n; i ++ ) 4for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] += f[i - 1][j - v[i]]; } 限定费用为定值; 12345678for (int i = 1; i <= m; i ++ ) f[0][i] = 0;f[0][0] = 1;for (int i = 1; i <= n; i ++ ) 4for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] += f[i - 1][j - v[i]]; } 限定费用下限; 12345678for (int i = 1; i <= m; i ++ ) f[0][i] = 0;f[0][0] = 1;for (int i = 1; i <= n; i ++ ) for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i - 1][j]; f[i][j] += f[i - 1][max(0, j - v[i])]; } 购买次数各物品均限购一次; 12345for (int i = 1; i <= n; i ++ ) for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]); } 购买次数不限; 12345678910for (int i = 1; i <= n; i ++ ) for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] = max(f[i][j], f[i][j - v[i]] + w[i]); }/*f[i][j] = max{f[i - 1][j], f[i - 1][j - v[i]] + w[i] ..., f[i - 1][j - maxk * v[i]] + maxk * w[i]};f[i][j - v[i]] = max{f[i - 1][j - v[i]], ..., f[i - 1][j - maxk * v[i]] + (maxk - 1) * w[i]};f[i][j] = max(f[i - 1][j], f[i][j - v[i]] + w[i]);*/ 各物品限购不同次数: ①,二进制$O(n\\times log_2s)$预处理各物品,物品维最多变为$O(n\\times log_2s)$,之后正常按限购一次处理,总时间复杂度即为$O(n\\times log_2s\\times V)$ 12345678910111213p.push_back({0, 0});while (n -- ){ int v, w, s; cin >> v >> w >> s; int t = 1; while (t <= s){ p.push_back({t * v, t * w}); s -= t; t <<= 1; } if (s) p.push_back({s * v, s * w});} ②,单调队列$O(1)$取得滑动窗口最值,总时间复杂度$O(n\\times V)$ 123456789101112for (int i = 1; i <= n; i ++ ) for (int j = 0; j < v[i]; j ++ ){ hh = 0, tt = -1; for (int k = j; k <= m; k += v[i]){ if (hh <= tt && q[hh] < k - s[i] * v[i]) hh ++ ; // when to pop_front while (hh <= tt && f[i - 1 & 1][q[tt]] - (q[tt] - j) / v[i] * w[i] <= f[i - 1 & 1][k] - (k - j) / v[i] * w[i]) tt -- ; // when to pop_back q[ ++ tt] = k; // push f[i & 1][k] = f[i - 1 & 1][q[hh]] + (k - q[hh]) / v[i] * w[i]; // front } }printf("%d\\n", f[n & 1][m]); 状态压缩每个当前状态f[i][j]的计算,使用到的是在物品维下的相邻前项的所有状态f[i - 1][0: m],即每次状态计算仅使用到上一个物品的体积维。每次状态计算中,物品维仅需记录一项,故可消去物品维。 每次计算使用到的是体积维中的前项,属于体积维中还未计算的状态,故状态计算遍历时,体积维需逆序。 123456789int f[M]; // 0 ~ mfor (int i = 0; i <= m; i ++ ) f[i] = 0;for (int i = 1; i <= n; i ++ ) 4for (int j = m; j >= v; j -- ) f[j] = max(f[j], f[j - v[i]] + w[i]);cout << f[m] << endl; 二维费用1234for (int i = 1; i <= n; i ++ ) for (int j = V1; j >= v1[i]; j -- ) for (int k = V2 - 1; k >= v2[i]; k -- ) f[j][k] = max(f[j][k], f[j - v1[i]][k - v2[i]] + w[i]); 具体方案物品维从大到小递推,求方案时就能从小到大反推,并且能选则选,即可得字典序最小方案 123456789101112131415161718for (int i = n; i >= 1; i -- ) for (int j = 0; j <= m; j ++ ){ f[i][j] = f[i + 1][j]; if (j >= v[i]) f[i][j] = max(f[i][j], f[i + 1][j - v[i]] + w[i]); }int p = m;bool flag = false;for (int i = 1; i <= n; i ++ ) if (p >= v[i] && f[i][p] == f[i + 1][p - v[i]] + w[i]){ if (!flag){ cout << i; flag = true; } else cout << ' ' << i; p -= v[i]; }cout << endl; e.g.宠物小精灵之收服1022. 宠物小精灵之收服 - AcWing题库 最优价值下的最高剩余费用 12345678for (int i = 1; i <= n; i ++ ) for (int j = V1; j >= v1[i]; j -- ) for (int k = V2 - 1; k >= v2[i]; k -- ) f[j][k] = max(f[j][k], f[j - v1[i]][k - v2[i]] + 1);cout << f[V1][V2 - 1] << ' ';int p = V2 - 1;while (p && f[V1][p - 1] == f[V1][V2 - 1]) p -- ;cout << V2 - p << endl; e.g.货币系统来源:532. 货币系统 - AcWing题库 遍历时计算得下一个物品是否可被前部物品组表示 123456789101112sort(a + 1, a + n + 1);int res = 0;m = a[n];memset(f, 0, sizeof(f));f[0] = true;for (int i = 1; i <= n; i ++ ){ if (!f[a[i]]) res ++ ; for (int j = a[i]; j <= m; j ++ ) f[j] |= f[j - a[i]];}printf("%d\\n", res); e.g.混合背包7. 混合背包问题 - AcWing题库 对于多重背包,用二进制优化处理为普通背包 123456789101112131415161718192021while (n -- ){ int v, w, s; cin >> v >> w >> s; if (s == 0){ for (int j = v; j <= m; j ++ ) f[j] = max(f[j], f[j - v] + w); } else{ if (s == - 1) s = 1; for (int k = 1; k <= s; k <<= 1){ for (int j = m; j >= k * v; j -- ) f[j] = max(f[j], f[j - k * v] + k * w); s -= k; } if (s){ for (int j = m; j >= s * v; j -- ) f[j] = max(f[j], f[j - s * v] + s * w); } }}cout << f[m] << endl; e.g.有依赖的背包问题10. 有依赖的背包问题 - AcWing题库 由于是深搜序,计算f[u][j]时,各子节点的f[son][0:m]都已算好。 遍历当前子节点的过程即相当于物品维限定在当前各子节点上,求考虑所有当前子节点下的最优价值,用滚动数组(备份数组)节省空间。 每次以分配给各单层子节点的体积做决策,视作分组背包过程,该父节点u在各体积j下的对各子节点的最优决策价值记在f[u][j]中,该价值又可能被更上一层(相对当前子节点来说的祖父层)用做分配以体积j所对应的最大价值。 123456789101112131415void dfs(int u){ for (int i = h[u]; ~i; i = ne[i]){ int son = e[i]; dfs(son); memcpy(g, f, sizeof(f)); for (int j = 0; j <= m - v[u]; j ++ ) for (int k = 0; k <= j; k ++ ) // 相当于分组背包的决策层,以所分配的体积作决策 f[u][j] = max(f[u][j], g[u][j - k] + f[son][k]); } memcpy(g, f, sizeof(f)); for (int i = 0; i <= m; i ++ ) if (i < v[u]) f[u][i] = 0; else f[u][i] = g[u][i - v[u]] + w[u];} e.g.背包问题求方案数11. 背包问题求方案数 - AcWing题库 所求的是对应最优价值的所有方案数。f与g的含义都是在限定费用上限的意义下的。 123456789for (int i = 0; i <= m; i ++ ) g[i] = 1; for (int i = 1; i <= n; i ++ ) for (int j = m; j >= v[i]; j -- ) if (f[j] < f[j - v[i]] + w[i]){ f[j] = f[j - v[i]] + w[i]; g[j] = g[j - v[i]]; } else if (f[j] == f[j - v[i]] + w[i]) g[j] = (LL)(g[j] + g[j - v[i]]) % mod;cout << g[m] << endl; e.g.能量石734. 能量石 - AcWing题库 决策内容包括选择哪些物品及选择顺序,可以发现最优解对应的物品选择顺序必定需要符合所发现的序。 f[i][j]表示考虑前i个物品,最终位于j时刻情况下的最优价值 12345678910111213141516171819202122232425262728293031323334353637383940414243#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;const int N = 110, M = 10010;int n;struct Node{ int s, e, l; bool operator<(const Node &W)const{ return s * W.l < W.s * l; }}p[N];int f[M];int main(){ int T; scanf("%d", &T); for (int C = 1; C <= T; C ++ ){ scanf("%d", &n); int m = 0; for (int i = 1; i <= n; i ++ ){ scanf("%d %d %d", &p[i].s, &p[i].e, &p[i].l); m += p[i].s; } sort(p + 1, p + n + 1); memset(f, -0x3f, sizeof(f)); f[0] = 0; for (int i = 1; i <= n; i ++ ) for (int j = m; j >= p[i].s; j -- ) f[j] = max(f[j], f[j - p[i].s] + p[i].e - (j - p[i].s) * p[i].l); int res = 0; for (int i = 0; i <= m; i ++ ) res = max(res, f[i]); printf("Case #%d: %d\\n", C, res); } return 0;} e.g.金明的预算方案487. 金明的预算方案 - AcWing题库 属于有依赖的背包问题,但依赖关系简单且最多有2个子节点,故可依子节点选择情况枚举遍历,视作一种分组背包。 1234567891011121314151617181920212223242526272829303132333435363738394041424344#include <iostream>#include <algorithm>#include <vector>#define v first#define w secondusing namespace std;typedef pair<int, int> PII;const int N = 110, M = 4e4 + 10;int n, m;PII mas[N];vector<PII> ser[N];int f[M];int main(){ cin >> m >> n; for (int i = 1; i <= n; i ++ ){ int v, w, p; cin >> v >> w >> p; if (!p) mas[i] = {v, v * w}; else ser[p].push_back({v, v * w}); } for (int i = 1; i <= n; i ++ ) for (int j = m; j >= 0; j -- ){ int sz = ser[i].size(); for (int k = 0; k < 1 << sz; k ++ ){ int v = mas[i].v, w = mas[i].w; for (int u = 0; u < sz; u ++ ) if (k >> u & 1){ v += ser[i][u].v; w += ser[i][u].w; } if (j >= v) f[j] = max(f[j], f[j - v] + w); } } cout << f[m] << endl; return 0;} 状态机模型e.g.大盗阿福1049. 大盗阿福 - AcWing题库 12345678910f[0][0] = 0;f[0][1] = -1e9;for (int i = 1; i <= n; i ++ ){ int t; cin >> t; f[i & 1][0] = max(f[i - 1 & 1][0], f[i - 1 & 1][1]); f[i & 1][1] = f[i - 1 & 1][0] + t;}cout << max(f[n & 1][0], f[n & 1][1]) << endl; e.g.股票买卖 IV1057. 股票买卖 IV - AcWing题库 12345678910memset(f, -0x3f, M * 2 * 4);for (int i = 0; i <= n - 1; i ++ ) f[i][0][0] = 0;for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= m; j ++ ){ f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1] + a[i]); f[i][j][1] = max(f[i - 1][j][1], f[i - 1][j - 1][0] - a[i]); }int res = 0;for (int i = 0; i <= m; i ++ ) res = max(res, f[n][i][0]);cout << res << endl; e.g.股票买卖 V1058. 股票买卖 V - AcWing题库 0:待卖;1:冻结待买;2:自由待买 12345678f[0][0] = f[0][1] = -1e9;f[0][2] = 0;for (int i = 1; i <= n; i ++ ){ f[i][0] = max(f[i - 1][0], f[i - 1][2] - a[i]); f[i][1] = f[i - 1][0] + a[i]; f[i][2] = max(f[i - 1][2], f[i - 1][1]);}cout << max(f[n][1], f[n][2]) << endl; 状态压缩模型e.g.蒙德里安的梦想来源:291. 蒙德里安的梦想 - AcWing题库 XXXX 线性DPe.g.编辑距离来源:899. 编辑距离 - AcWing题库 XXXX 区间DP树形DP数位DPe.g.整数划分来源:900. 整数划分 - AcWing题库 XXXX 图论搜索e.g.奶牛选美来源:2060. 奶牛选美 - AcWing题库 XXXX e.g.拖拉机来源:2019. 拖拉机 - AcWing题库 XXXX e.g.贝茜的复仇来源:1875. 贝茜的报复 - AcWing题库 XXXX 连通性拓扑序最短路MST二分图数据结构单调队列e.g.滑动窗口来源:154. 滑动窗口 - AcWing题库 XXXX 并查集e.g.食物链来源:240. 食物链 - AcWing题库 XXXX e.g.银河英雄传说来源:238. 银河英雄传说 - AcWing题库 XXXX 字典树e.g.最大异或对来源:143. 最大异或对 - AcWing题库 XXXX 线段树e.g.一个简单的整数问题2来源:243. 一个简单的整数问题2 - AcWing题库 XXXX 平衡树树状数组e.g.一个简单的整数问题2来源:243. 一个简单的整数问题2 - AcWing题库 XXXX 数学快速幂XXXX 费马小定理对于整数a、p,若p是质数且a不是p的倍数,那么有$a^{p-1}=1(mod~p)$成立。 等式左边同分出一个a,则有$a\\cdot a^{p-2}=1$,从而有:**对于给定质数p,所有不是p倍数的整数a的模p逆元为a的p-2次方$a^{p-2}$**。 e.g.爬树的甲壳虫来源:2022年4月第十三届蓝桥杯C/C++程序设计A组(省赛) XXXX 扩展欧几里得矩阵乘法博弈基础算法贪心e.g.区间选点来源:905. 区间选点 - AcWing题库 XXXX e.g.货仓选址来源:104. 货仓选址 - AcWing题库 XXXX e.g.耍杂技的牛来源:125. 耍杂技的牛 - AcWing题库 XXXX 差分离散化二分XXXX e.g.青蛙过河来源:2022年4月第十三届蓝桥杯C/C++程序设计A组(省赛) XXXX e.g.粉刷栅栏来源:1987. 粉刷栅栏 - AcWing题库 XXXX e.g.金发姑娘和N头牛来源:1952. 金发姑娘和 N 头牛 - AcWing题库 XXXX e.g.救生员来源:1750. 救生员 - AcWing题库 XXXX 双指针e.g.愤怒的奶牛来源:1855. 愤怒的奶牛 - AcWing题库 位运算高精度其他手动O2优化#pragma GCC optimize(2,”inline”) e.g.岛来源:2014. 岛 - AcWing题库 XXXX","link":"/2022/11/11/%E6%87%B5%E6%87%82%E9%98%B6%E6%AE%B5%E6%80%BB%E7%BB%93/"}],"tags":[{"name":"brand-new","slug":"brand-new","link":"/tags/brand-new/"},{"name":"md-learning","slug":"md-learning","link":"/tags/md-learning/"},{"name":"hexo-learning","slug":"hexo-learning","link":"/tags/hexo-learning/"},{"name":"icarus","slug":"icarus","link":"/tags/icarus/"},{"name":"blog","slug":"blog","link":"/tags/blog/"},{"name":"动态规划","slug":"动态规划","link":"/tags/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92/"},{"name":"图论","slug":"图论","link":"/tags/%E5%9B%BE%E8%AE%BA/"},{"name":"数据结构","slug":"数据结构","link":"/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"},{"name":"数学","slug":"数学","link":"/tags/%E6%95%B0%E5%AD%A6/"},{"name":"基础算法","slug":"基础算法","link":"/tags/%E5%9F%BA%E7%A1%80%E7%AE%97%E6%B3%95/"}],"categories":[{"name":"probe","slug":"probe","link":"/categories/probe/"},{"name":"usage","slug":"usage","link":"/categories/usage/"}]}