
动态规划
文章平均质量分 57
加油
河林山
这个作者很懒,什么都没留下…
展开
-
[NOI2002]Robot(欧拉函数+DP)
计蒜客之提交链接题意:——默认你已仔细阅读过题干,并且了解欧拉函数。简化版题意:——题目已给出 m 的质因数分解式,找 m 的所有约数,约数可分为3类(政客,军人,学者),每个约数只能代表三者其一。即:所以政客+所有军人+所有学者==m的所有约数。注意:所有约数中不包括1,因为 1 不属于三者中任意一个。——所求:所有政客的独立数之和,所有军人的独立数之和,所有学者的独立数之和。质因数分解式就是找约数使用的。注释:独立数:x 的独立数:就是 x 的欧拉函数值。政客:能分解成偶数个不同原创 2022-04-07 11:44:45 · 916 阅读 · 1 评论 -
收集金币(简单dp)
思路:dp转载大佬思路代码:#include<bits/stdc++.h>using namespace std;const int N=20010;int a[N],f[N][2];int main(){ int T;scanf("%d",&T); while(T--) { int n;scanf("%d",&n); char s[5];int x; for(int i=1;i<=n;i++) { scanf("%s %d".转载 2021-11-25 22:03:06 · 464 阅读 · 0 评论 -
信号传输(简单dp+二分)
大佬解析我的代码:(未测试)#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+110; ll a[N],dp[N],n,w;bool ok(ll x){ memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { dp[i]=dp[i-1];//不选择第i个城市建基站 //选择第i个城市建基站 if(i-x转载 2021-10-29 15:56:20 · 193 阅读 · 0 评论 -
采药(01背包二维数组详细解释版||一维数组略解吧)
vjudge提交链接题目:采药——辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师。为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。医师把他带到一个到处都是草药的山洞里对他说:“孩子,这个山洞里有一些不同的草药,采每一株都需要一些时间,每一株也有它自身的价值。我会给你一段时间,在这段时间里,你可以采到一些草药。如果你是一个聪明的孩子,你应该可以让采到的草药的总价值最大。” 如果你是辰辰,你能完成这个任务吗?Input——输入第一行有两个整数T(1 <= T原创 2021-03-13 13:52:59 · 183 阅读 · 0 评论 -
最基础模版01背包,花最多的钱吃更多的菜
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。Input多组数据。对于每组数据:第一行为正整数n,表示菜的数量。n<=1000。第二行包括n个正整数,表示每种菜的价格。价格不超过50。第三行包括一个正整数m,原创 2020-09-26 09:31:33 · 152 阅读 · 0 评论 -
省钱构建回文串
Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will read as the cows pass by a scanner. Each ID tag’s contents are currently a singl原创 2020-09-26 09:14:42 · 1152 阅读 · 0 评论 -
求区间最长递减序列(可不连续)
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are原创 2020-09-26 08:38:35 · 197 阅读 · 0 评论 -
dp,求最长公共子序列(可不连续的)
求最长公共子序列(可不连续的)A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, …, xm> another sequence Z = <z1, z2, …, zk> is a subsequence of X if there exists a strictly incr原创 2020-09-26 08:19:17 · 103 阅读 · 0 评论 -
01背包,我可不想被抓啊
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before原创 2020-09-26 08:58:32 · 131 阅读 · 0 评论