随笔分类 - 动态规划
基础算法
摘要:P5020 [NOIP2018 提高组] 货币系统 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int MAXAI=25005; const int MAXN=105; int f
阅读全文
摘要:p1616 疯狂的采药 #include<iostream> #include<vector> using namespace std; const int Maxn=10000001; int a[Maxn],b[Maxn],dp[Maxn]; int main() { // freopen("p
阅读全文
摘要:完全背包 此类背包问题中,我们的每种物品有无限多个,可重复选取。 类似于01背包,我们依旧需要考虑前i-1件物品的影响。 此时我们依旧可以设得二维状态 f[i][v]代表用i件物品填充为体积为v的背包得到的最大价值 依旧很容易写出状态转移方程 f[i][v]=max(f[i−1][v],f[i−1]
阅读全文
摘要:P1926 小书童——刷题大军 #include<iostream> #include<algorithm> using namespace std; int dp[200]; int a[20],b[20],c[20]; int n,m,k,r; int main() { cin>>n>>m>>k
阅读全文
摘要:P2639 [USACO09OCT]Bessie's Weight Problem G #include<iostream> using namespace std; long long dp[45001]; int s[501]; int main() { int N,H; cin>>H>>N;
阅读全文
摘要:P2871 [USACO07DEC]Charm Bracelet S #include<iostream> using namespace std; long long dp[12881]; int D[3500],W[3500]; int main() { int N,M; cin>>N>>M;
阅读全文
摘要:P2925 [USACO08DEC]Hay For Sale S #include<iostream> using namespace std; long long dp[50001]; int h[5001]; int main() { int C,H; cin>>C>>H; for (int i
阅读全文
摘要:P1802 5 倍经验日 #include<iostream> #include<cstring> using namespace std; const int Maxn=1100; long long dp[Maxn],lose[Maxn],win[Maxn],used[Maxn]; long l
阅读全文
摘要:P1877 [HAOI2012]音量调节 #include<cstdio> using namespace std; int n,begin,maxlevel; int ans; int a[51]; bool f[51][1001]; int main() { scanf("%d%d%d",&n,
阅读全文
摘要:P1510 精卫填海 #include<iostream> using namespace std; long long dp[45001]; int s[10001],t[10001]; int main() { int v,n,c; cin>>v>>n>>c; for (int i=1;i<=n
阅读全文
摘要:P1048 [NOIP2005 普及组] 采药解法一 #include<iostream> #include<cstring> using namespace std; const int Maxn=110; const int Maxv=1010; int V,n,ans=0; int w[Max
阅读全文
摘要:01背包给定 n 件物品,物品的重量为 w[i],物品的价值为 c[i]。现挑选物品放入背包中,假定背包能承受的最大重量为 V,问应该如何选择装入背包中的物品,使得装入背包中物品的总价值最大?搜索算法状态i表示考虑第i件物品,v表示当前背包重量,C表示当前最大价值。dfs(i,v,C)调用方式dfs
阅读全文
摘要:走楼梯问题题目:有一座高度是10级台阶的楼梯,从下往上走,每跨一步只能向上1级或者2级台阶。要求用程序来求出一共有多少种走法。比如,每次走1级台阶,一共走10步,这是其中一种走法。我们可以简写成 1,1,1,1,1,1,1,1,1,1。再比如,每次走2级台阶,一共走5步,这是另一种走法。我们可以简写
阅读全文