动态规划
文章平均质量分 56
人工智鸭
这个作者很懒,什么都没留下…
展开
-
树上dp(题单)有做到就加进来
1.牛客小白月赛45-E第一道接触的树上dp.题意:给定你一个n个节点的树,你需要在树上选取一个非空连通块,使其舒适度和最大。选择的边和点的舒适度都是舒适度。代码:void dfs(int now,int fa){ dp[now]=a[now]; for(int i=h[now];~i;i=nx[i]){ int to=e[i]; if(to==fa)continue; int w=value[i]; dfs(..原创 2022-04-25 22:22:01 · 126 阅读 · 0 评论 -
牛客寒假训练营4-爆炸的符卡洋洋洒洒 (dp变形)
题意:链接:登录—专业IT笔试面试备考平台_牛客网来源:牛客网小红正在研究如何把符卡组合出尽可能大威力的组合魔法。小红共有 n种符卡可以选择,每种符卡最多只能选择一次,每个符卡的魔力消耗为 ai,威力为 bi。如果将多个符卡进行组合,则可以发动一个组合魔法。组合魔法的魔力消耗为选择的符卡的魔力消耗的总和,其威力为选择的符卡的威力的总和。小红必须保证最终符卡的魔力消耗总和为 k 的倍数,否则小红将受到魔力反噬而发动魔法失败。小红想知道,自己能发动的组合魔法最大的威力是多少?..原创 2022-02-25 21:10:33 · 445 阅读 · 0 评论 -
牛客训练营3-智乃买瓜(anthor version) dp还原为原背包
题目描述已经知道购买质量为1 2 3 .....m的瓜的方案数,对于每一个瓜,我们可以选择买整个,买半个,不买。保证每个瓜质量为偶数。思路:这道题的的原版本是已知道每个瓜的质量求方案数,直接进行背包即可。对于这道题是他的逆向求解,我们从小到大枚举每一个方案数,如 样例1 2 1 3 2 1,说明买质量为1的瓜方案数有1,这就说明一定有一个瓜质量为2切一半后达到这个方案数,于是我们将2加入答案序列,并对样例消除2这个瓜后进行更新。代码#include<bits/stdc++.h&.原创 2022-02-25 16:59:12 · 394 阅读 · 0 评论 -
E-CD(01背包+记忆化搜索)
You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is on CDs. You need to have it on tapes so the problem to solve is: you have a tape N minutes long. How to choose tracks from CD to get most out of tape space a原创 2022-02-06 18:05:57 · 392 阅读 · 0 评论 -
L-add one (动态规划)
You are given an integernn. You have to applymmoperations to it.In a single operation, youmustreplace every digitddof the number with the decimal representation of integerd+1. For example,1912becomes21023after applying the operation once.Yo...原创 2022-02-06 17:25:15 · 339 阅读 · 0 评论