摘要: #include using namespace std; const int INF=0x3f3f3f3f; int a[1000],b[1000],ans=0,dp[101][200000+10],n,off=100000;//直接偏移,省事 //有两个量互相制约,两个量都单独的条件,这种类型,可以假设一个量不变然后dp数组,dp数组的值是b的最优值,这样通过一个数组把a的和,b的和联系在... 阅读全文
posted @ 2020-06-06 21:01 西伯利亚挖土豆 阅读(255) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; // 走两次是不行的,因为这就是贪心了。。 // 需要多线程dp,就是想象有2个人同时走,他们可以走到一起,但是必须只加一次; // 转移方程: // (1)a,b都从上/下走过来 // (2)a,b一个上一个下走过来 // 共4种 //dp 数组代表a到哪,b到哪,可以不一样 int dp[11][11][11][11]={0},a[... 阅读全文
posted @ 2020-06-06 21:00 西伯利亚挖土豆 阅读(181) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; //和方格取数一样,一来一回可以看成走两次 int a[51][51],m,n,dp[51][51][51][51]={0}; int main() { cin>>m>>n; for(int i=1;i>a[i][j]; for( int x1 = 1; x1 <= m; x1++ ) { for( int y... 阅读全文
posted @ 2020-06-06 20:59 西伯利亚挖土豆 阅读(173) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; const int maxn=1000+10; int n,k,w[maxn],v[maxn],dp[10*maxn]={0},nw[10*maxn],nv[10*maxn],cnt=0,c[maxn]; //计算出完全背包最多多少个,就变成了多重背包,01页看成多重,直接用二进制变成01,然后dp //也可以完全背包不转化,用标记来和... 阅读全文
posted @ 2020-06-06 20:58 西伯利亚挖土豆 阅读(107) 评论(0) 推荐(0) 编辑
摘要: #include <bits/stdc++.h> using namespace std; int dp[1000][1000],n,m,v[1000][1000]={0},w[1000][1000]={0}; //dp 表示前i组容量为j //有N件物品,告诉你这N件物品的重量以及价值,将这些物品划分为K组,每组中的物品互相冲突,最多选一件, // 求解将哪些物品装入背包可使这些物品的费用综合不 阅读全文
posted @ 2020-06-06 20:58 西伯利亚挖土豆 阅读(146) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; const int N=100+10; //二维代价的背包问题,就是dpi,j,k 太大了,用滚动数组 //注意滚动数组倒着遍历j int n,dp[N][N]={0},w[N],m[N],v[N],V,M; int main() { cin>>n>>V>>M; for(int i=1;i>w[i]>>m[i]>>v[... 阅读全文
posted @ 2020-06-06 20:56 西伯利亚挖土豆 阅读(119) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; const int maxn=1000+10; int n,k,w[maxn],v[maxn],dp[11*maxn]={0},nw[11*maxn],nv[11*maxn],cnt=0,c[maxn]; //01背包二进制拆分 //普通拆分,就是把多重的物品看成好几个独立的不同的物品,这样物品变成n+sum(ki)个,考虑二进制的特性... 阅读全文
posted @ 2020-06-06 20:55 西伯利亚挖土豆 阅读(191) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; const int maxn=1000+10; int n,k,w[maxn],v[maxn],dp[maxn][maxn]={0},c[maxn]={0}; int main() { cin>>n>>k; for(int i=1;i>w[i]>>v[i]>>c[i]; for(int i=1;i=p*w[i])... 阅读全文
posted @ 2020-06-06 20:55 西伯利亚挖土豆 阅读(101) 评论(0) 推荐(0) 编辑
摘要: #include using namespace std; //算法提高 种树 //这是01背包问题的变形 //环的处理方法 1.找到最小值的位置,预处理数组,比如 56 21 64 32 45 -> 21 64 32 45 56 21 //这样就相邻了而且21 21肯定不会同时选到 //2.还可以:第一个和最后一个只会选一个, //那么就对 1...n-1 2...n进行处理,然后求最大值,... 阅读全文
posted @ 2020-06-06 20:54 西伯利亚挖土豆 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 01背包输出字典序最小的最优解 阅读全文
posted @ 2020-06-06 20:53 西伯利亚挖土豆 阅读(334) 评论(0) 推荐(0) 编辑