![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DP
Alberttttt
这个作者很懒,什么都没留下…
展开
-
hdu 2602 01背包
题目链接:传送门 参考博客:点击打开链接 能理解递推关系式但对代码不是很理解。。 #include #include #define maxn 1005 using namespace std; int dp[maxn][maxn],a[maxn],v[maxn]; int main() { int i,j,t,n,vn; while(cin>>t) {转载 2017-08-01 09:43:08 · 170 阅读 · 0 评论 -
hdu1171 01背包
题目链接:点击打开链接 题目是给出物体的价值和数量要求物品最优平均分,前面的不下于后面的。 思路:可以这么想,求sum/2的最大值,就是先求平分的最大值就好了。 #include #include #include using namespace std; const int maxn=1e6; int a[maxn],dp[maxn]; int main() { int i,原创 2017-08-04 16:33:50 · 270 阅读 · 0 评论 -
hdu1114 完全背包
题目链接:点击打开链接 题意:给出小猪钱罐的重量和装满钱后的重量,然后是几组数据,每组数据包括每种钱币的价值与重量 要求出重量最少能装满钱罐时的最大价值 思路:因为个数不限,所以是完全背包问题。背包九讲讲的算清楚的,这里只是求最小值。 注意dp[0]的初始化! #include #include using namespace std; const int maxn=1e5; int原创 2017-08-04 18:44:33 · 227 阅读 · 0 评论 -
hdu1428 BFS+记忆化搜素
题目链接:点击打开链接 先用BFS把最短路找出来,然后记忆化搜索就好了 #include #include #include #include #include #define LL long long using namespace std; const int maxn=60; const int xx[]={0,0,1,-1}; const int yy[]={1,-1,0,0}; L原创 2017-08-19 19:57:50 · 281 阅读 · 0 评论 -
csu1106记忆化搜索
题目链接点击打开链接 题意:求关于副对角线对称的最短路径的总数。 思路:和我上午做的hdu的基本一模一样原创 2017-08-20 01:34:52 · 201 阅读 · 0 评论 -
hdu2084 DP入门
题目链接:点击打开链接 这题和白皮的数字三角形是一样的。有很多题都是这个的变形比如1176 递归: #include #include #include using namespace std; const int maxn=1e2+10; int a[maxn][maxn],d[maxn][maxn],n; int dp(int i,int j) { if(d[i][j]>0)r原创 2017-08-07 09:56:45 · 189 阅读 · 0 评论 -
NYoj16 矩形嵌套 DAG上的Dp
题目链接:点击打开链接 刘汝佳的小白皮的DAG矩形嵌套问题,但不要输出字典序最小路径 #include #include #include typedef struct node { int x,y; //x长y宽 } node; using namespace std; const int maxn=1000+10; int n,Max; node a[maxn]; int d[ma原创 2017-08-07 15:37:13 · 327 阅读 · 0 评论 -
hdu1024求n个数分成k段的最大子序列和
题目链接点击打开链接 给你n个数,求分成m个子序列的最大和 先贴别人的代码,我看不懂,之后再理解理解 /* 状态dp[i][j]有前j个数,组成i组的和的最大值。决策: 第j个数,是在第包含在第i组里面,还是自己独立成组。 方程 dp[i][j]=Max(dp[i][j-1]+a[j] , max( dp[i-1][k] ) + a[j] ) 0<k<j 空间复杂度,m未知,n<=10000转载 2017-08-24 22:58:26 · 1270 阅读 · 0 评论 -
hdu1243求最长公共字串的权值
题目链接:点击打开链接 求最长公共子串的长度模板 char s1[maxn],s2[maxn]; int dp[maxn][maxn]; //求串s1和串s2的公共子序列 int lcs(char *s1,char *s2) { int len1 = strlen(s1); int len2 = strlen(s2); for(int i = 0; i <= len1;原创 2017-08-25 00:00:54 · 321 阅读 · 0 评论 -
hdu 1069
题目链接:点击打开链接 题意: 一堆科学家研究猩猩的智商,给他M种长方体,每种N个。 然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉。 现在给你M种长方体,计算,最高能堆多高。 要求位于上面的长方体的长要大于下面长方体的长,上面长方体的宽大于下面长方体的宽。 思路:每个长方体都是无限的,所以一个长方体等于有三个不同的,相当与求长和宽严格递减的最大高之和。 #includ原创 2017-08-14 23:27:45 · 255 阅读 · 0 评论 -
csu1120 Lics(模板)
题目链接:点击打开链接 求最长递增公共子序列长度 #include #include #include using namespace std; const int maxn=1e3+10; int n,m,a[maxn],b[maxn],dp[maxn][maxn];//a数组的长度n,b数组的长度为m,都是从1开始 int LICS() { int MAX,i,j;原创 2017-08-21 22:31:23 · 226 阅读 · 0 评论 -
hdu1423 Lics
题目链接:点击打开链接 模板题 #include #include #include using namespace std; const int maxn=1e3+10; int n,m,a[maxn],b[maxn],dp[maxn][maxn];//a数组的长度n,b数组的长度为m,都是从1开始 int LICS() { int MAX,i,j; memset(dp原创 2017-08-21 22:46:33 · 292 阅读 · 0 评论 -
hdu1074 状压DP
题目链接点击打开链接 第一次做状态压缩的题,感觉是吧所有情况转化为二进制在DP; 这题的d[i]表示的是i转换为二进制对应位置的状态的最小罚值。 状态转移d[i]=min(d[i-1 d[i-1 这个状态方程的意思是,这个状态是从前一个状态出来的,前一个状态就是有一个作业是放到最后做的,所以要加上那个作业的罚值。 #include #include #include using na原创 2017-08-15 14:31:00 · 275 阅读 · 0 评论 -
hdu1160 LIS
题目链接:点击打开链接 题意:找到一种最长序列,满足老鼠的体重严格递增,速度严格递减。输出其中一种路径即可。 排序之后按LIC做就行。 #include #include #include #include using namespace std; const int maxn=1e3+10; const int INF=0x3f3f3f3f; typedef struct mice {原创 2017-08-15 16:19:31 · 341 阅读 · 0 评论 -
hdu1158枚举PD
题目链接:点击打开链接 题意:项目经理想确定每个月需要的工人人数。他知道每个月需要的工人人数最少。当他雇用或解雇工人时,会有一些额外的费用。一旦雇用了工人,即使他不工作,他也会得到工资。经理知道雇用工人,解雇工人和工人的工资的费用。那么经理会面对这样一个问题:每个月要雇用或解雇多少个工人,以保持项目总成本最低。 思路:枚举每一种状态,求最小费用。 这个d[i][j]表示第i个月有j个工人并且原创 2017-08-15 22:50:12 · 238 阅读 · 0 评论 -
hdu1165
题目链接点击打开链接 题意按公式求A(m,n)的值; 我开始用DP,结果wa了,后面看别人的找规律,这难道不是和DP一样的吗,而且d3的n #include #include #include #include using namespace std; int d[4][1000002]; void init() { int i; d[0][0]=1;d[1][0]=2;d[2]原创 2017-08-15 20:42:37 · 419 阅读 · 0 评论 -
hdu1331记忆化搜索
题目链接:点击打开链接 题意:求给的公式。 思路:记忆化搜索,暴力跑出来 #include #include #include using namespace std; const int maxn=20+2; int d[maxn][maxn][maxn],vis[maxn][maxn][maxn]; int w(int a,int b,int c) { if(a<=0||b<=原创 2017-08-18 11:24:02 · 544 阅读 · 0 评论 -
hdu1159 最大公共子序列(lcs) hdu 1080
题目链接: hdu1159 点击打开链接 题意:给你两个字符串,求lcs 首先lcs的递推关系式是;d[i][j](以i为结尾的子序列1和以j为结尾的子序列2的最大公共子序列) d[i-1][j-1]+1 (s1[i]==s2[j]) d[i][j]= { max(d[i-1][j],d[i][j-1]) (s1[i原创 2017-08-09 21:57:12 · 355 阅读 · 0 评论 -
hdu1176
题目链接:点击打开链接 题目可以转换为开始是从a[0][5],开始的,每秒可以向下,左下,和右下走,求大和,就是变向的灯塔问题。 #include #include #include using namespace std; const int maxn=1e5+10; int a[100000+5][11]; int main() { int n,i,j,x,t,fl; w原创 2017-08-01 11:06:24 · 234 阅读 · 0 评论 -
poj1088 Dp,记忆化搜索
题目链接:点击打开链接 思路很简单就是找上下左右值比他小的最长路径+1,即d[i][j]=max(d[i][j-1],d[i-1][j],d[i+1][j],d[i][j-1])+1(以值比他小为前提)。 边界就是到了矩形外面,返回len=0; #include #include #include using namespace std; const int maxn=100+10; in原创 2017-08-08 10:22:12 · 374 阅读 · 0 评论 -
hdu1506求最大子矩阵
题目链接:点击打开链接 看的别人的代码写的:点击打开链接 #include #include #define LL long long using namespace std; const int maxn=1e6+10; LL a[maxn],l[maxn],r[maxn]; int main() { LL n,Max,i,t; while(~scanf("%lld",&n转载 2017-08-08 13:22:10 · 227 阅读 · 0 评论 -
hdu1505
题目链接:点击打开链接 题意: 给你一个M*N的区域。R代表被占用,F代表空闲。求最大矩形面积*3; 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 (F=1,R=0,方便求和) 1 2 2 2 2 2 0 0 0 1 1 1 转化完就是右边矩阵 0 0 0 3 3 3 1 1原创 2017-08-08 16:32:47 · 343 阅读 · 0 评论 -
hdu1058
题目链接:传送门 humble numbers是之含2,3,5,7这几个因子的数,要你求前5842个这种数。 首先从特殊的1开始,后面都是前面数乘2,3,5,7.这里很巧妙的用了指针的思想,用l1,l2,l3,l4都指向开始的数1,排一个,该指针向后推一个,这样不仅能按顺序排而且可以减少很多的计算。 #include #include using namespace std; int原创 2017-08-01 19:19:06 · 316 阅读 · 0 评论 -
hdu1257
题目链接:传送门 #include using namespace std; const int maxn=30000+3; int a[maxn],d[maxn]; int main() { int n,i,j,cunt; while(cin>>n) { cunt=1; cin>>a[0]; d[0]=a[0]; for(原创 2017-08-01 19:28:09 · 271 阅读 · 0 评论 -
hdu1224
题目链接:点击打开链接 题意: 是有n个城市,每个城市有一个魅力值,要你从第一个城市出发,每次只能到比你所在城市标号大的城市,最后到下标为n+1的城市(就是1城市),求缩经过的城市最大魅力值之和。 思路:把每种情况列出来就好了 #include #include #include #include using namespace std; const int maxn=100+10; c原创 2017-08-16 10:05:22 · 214 阅读 · 0 评论 -
hdu 1059 多重背包
题目链接:点击打开链接 题目给你若干数目的1,2,3,4,5,6的数目,求能不能平分。 直接套模板。。。。。哈哈哈哈哈 #include #include #include using namespace std; int c[110],w[110],m[110],f[100010],v; //c[]:物品所占容量;w[]物品的价值;m[]物品的数量;V为背包容量 void ZeroOne原创 2017-08-08 22:47:34 · 174 阅读 · 0 评论 -
01背包,完全背包,多重背包
1. 01背包 每种物品仅有一件,可以选择放或不放。 for(i=1;i<=n;i++) for(j=vn;j>=v[i];j--) dp[j]=max(dp[j],dp[j-v[i]]+a[i]); 2.完全背包: 有 N 种物品和一个容量为 V 的背包,每种物品都有无限件可用。第 i 种物品的费用是原创 2017-08-04 22:30:10 · 168 阅读 · 0 评论 -
hdu1078
题目链接:点击打开链接 题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)上有一些吃的,FatMouse从(0,0)的位置出发去找吃的,并且每次最多走k步,在他走过的地方就可以吃掉吃的,保证吃的数量在0-100之间,而规定是他只能水平或者垂直走,而且每走一步,下一步的吃的数量是需要大于此刻所占的位置,问FatMouse最后最多可以吃多少吃的。 我开始看错题了,以为是每次只能走k原创 2017-08-09 09:25:35 · 452 阅读 · 0 评论 -
hdu1081
题目链接:点击打开链接 给你一个N*N的矩阵,求最大子矩阵 用别人的模板交的 #include #include #include using namespace std; int map[110][110],dp[110][110]; int main() { int N,a; while(~scanf("%d",&N) && N) { memse转载 2017-08-09 09:45:56 · 214 阅读 · 0 评论 -
hdu1025 LIS
题目链接:点击打开链接 题目是给你匹配对,第i个穷人城市需要第j个富人城市的帮助,穷人与富人城市是平行线,要求不能有交叉,比如1—>2,2->1是不行的,求最多能被帮助的城市数量。 思路:可看成LIS问题。 代码是别人的模板代码 #include #include using namespace std; const int maxn=500000+10; int Arr[maxn],L转载 2017-08-09 10:39:49 · 197 阅读 · 0 评论 -
hdu2546 01背包
题目链接:点击打开链接 把最大的减去就是01背包了; #include #include #include using namespace std; const int maxn=1e3+10; int a[maxn],dp[maxn]; int main() { int m,i,j,n,k,v,Max,pos; while(cin>>n&&n) {原创 2017-08-02 14:56:35 · 258 阅读 · 0 评论 -
hdu2955 01背包
题目链接:点击打开链接 看的别人的思路写的。。。点击打开链接 #include #include using namespace std; const int maxn=1e5+10; int m[maxn]; int main() { int t,i,j,n,sum; double p0,p[maxn],dp[maxn]; cin>>t; while(原创 2017-08-02 16:48:21 · 181 阅读 · 0 评论 -
poj3624 01背包裸题
题目链接:点击打开链接 #include #include using namespace std; const int maxn=3500; int a[maxn],v[maxn],dp[12900+10]; int main() { int n,m,i,j; while(cin>>n>>m&&n) { for(i=1;i<=n;i++) {原创 2017-08-02 16:51:04 · 409 阅读 · 0 评论 -
hdu2103 01背包
题目链接:点击打开链接 和poj2599差不多的题目,就是要把递推关系要转化为求最小拿不到offer的概率。 #include #include #include using namespace std; const int maxn=1e5; double p[maxn],dp[maxn]; int a[maxn]; int main() { int m,n,i,j; wh原创 2017-08-02 17:57:07 · 287 阅读 · 0 评论 -
hdu1208
题目链接:点击打开链接 题目是要求从左上角到右下角的路径数,只能向下或者向右走方格里的数; #include #include #include #include using namespace std; const int maxn=35; const int INF=0x3f3f3f3f; char m[maxn][maxn+10]; long long d[maxn][maxn],vi原创 2017-08-16 09:02:12 · 248 阅读 · 0 评论